Dynamic attributes
Dynamic attributes (attrs
)
The format consists in key
as the name of the attribute and the value is a tuple of three elements with the condition:
<field name="field_name" attrs="{'invisible': [('other_field', '=', False)]}" />
It is possible to use value from the form in the condition
<field name="field_name" attrs="{'invisible': [('other_field', '=', field3)]}" />
JSON Dynamic attributes (json_attrs
)
It uses the conschek library to evaluate the conditions.
Ant the format consists of a JSON with the following structure:
{ "condition": "AND", "rules": [ { "field": "other_field", "operator": "=", "value": false } ]}
Inside the xml will be like this:
<field name="field_name" json_attrs="{'invisible': {'condition': 'AND', 'rules': [{'field': 'other_field', 'operator': '=', 'value': false}]}}" />
It is possible to use value from the form in the condition
{ "condition": "AND", "rules": [ { "field": "other_field", "operator": "=", "value": "$field3" } ]}
And is possible to nest conditions
{ "condition": "AND", "rules": [ { "condition": "OR", "rules": [ { "field": "age", "operator": "<", "value": 18 }, { "field": "age", "operator": ">", "value": 65 } ] }, { "field": "citizenship", "operator": "=", "value": true } ]}