nadjib
Janvier 10, 2023, 9:48
1
Hi everyone,
I’m trying to developp a small module, and the issue i’m facing is filtering on a field based on another field’s value.
<entity name="Employee">
<string name="firstName" title="First Name" required="true" unique="true" min="2"/>
<string name="lastName" title="Last Name" required="true" unique="true" min="2"/>
<string name="fullName" namecolumn="true" search="firstName,lastName">
<![CDATA[
if (firstName == null && lastName == null)
return null;
return firstName + " " + lastName;
]]>
</string>
<string name="jobtitle" title="Job Title" min="2"/>
<many-to-one name="site" title="Site" required="true" ref="Site"/>
<many-to-one name="department" title="Department" ref="Department"/>
<finder-method name="findByName" using="fullName" />
</entity>
<entity name="Department">
<string name="name" title="Name" required="true" unique="true" min="2"/>
<many-to-one name="site" ref="Site"/>
<string name="description" title="Description" multiline="true" default=""/>
</entity>
<entity name="Site">
<string name="code" title="Code" required="true" unique="true" min="2"/>
<string name="name" title="Name" required="true" unique="true" min="2"/>
<string name="description" title="Description" multiline="true" default=""/>
<string name="address" title="Address" multiline="true" default=""/>
</entity>
<form name="employee-form" title="Employee" model="com.axelor.assetmanager.db.Employee">
<panel title="Employee Details">
<field name="firstName"/>
<field name="lastName"/>
<field name="jobtitle"/>
</panel>
<panel title="Affectation">
<field name="site"/>
<field name="department" **domain="self.site == site"**/>
</panel>
</form>
And what I want is whene creating an employee, the department field shows only departments that belong to the selected site.
I tried to use domain but it gives me an error.
PHPierre
(Pierre Mayeux)
Janvier 11, 2023, 8:28
2
Can you edit your post to add the error you meet ?
nadjib
Janvier 11, 2023, 5:49
3
I’ve solved it using action-attrs
<field name="site" onChange="action-employee-site-change"/>
<action-attrs name="action-employee-site-change">
<attribute for="department" name="domain" expr="self.site = :site"/>
</action-attrs>
PHPierre
(Pierre Mayeux)
Janvier 11, 2023, 6:51
4
You don’t need to use a action-attrs for this, but you should use an action-record to reset your department if you change your site.
<field name="site" onChange="reset-department" />
<field name="department" domain="self.site = :site" />
<action-record name="reset-department" ...>
<field name="department" expr="eval: null"/>
</action-record>
nadjib
Janvier 11, 2023, 8:12
5
It’s not about reseting the department , but to be able to select only departments that belongs to the selected site .
PHPierre
(Pierre Mayeux)
Janvier 12, 2023, 8:50
6
Yeah, I get it. But what happen if you select a site A and department A1 whoch belong to A. If you switch to the site B, A1, doesn’t belong to B so you need to reset your department, right ?
nadjib
Janvier 12, 2023, 6:00
7
Ummm, that’s right.
Ok well, i got it. And the code you’ve provided works just fine.
But i have a question : why using action-record instead of action-attrs ?
<action-attrs name="action-employee-reset-department">
<attribute for="department" name="value" expr="eval: null"/>
<attribute for="department" name="domain" expr="self.site = :site" if="site"/>
</action-attrs>
PHPierre
(Pierre Mayeux)
Janvier 13, 2023, 8:50
8
action-record is useful **for create, update data in the current form while action-attrs docus on editing how the form is working.
With action-record , you edit the value of field while with action-attrs you edit how the field is working.
Obvioulsy, you can use action-method to reproduce what action-record and action-attrs but in JAVA. You can manage the ActionResponse
object in each method.
Hope my explanations are clear. I can provide you examples in you want more details.
system
(system)
A fermé ce sujet ()
Février 12, 2023, 8:51
9
Ce sujet a été automatiquement fermé après 30 jours. Aucune réponse n’est permise dorénavant.