Does anyone know if it is possible to implement a conditional attribute on a field?
For example:
<field name="name"/>
And if condition is met:
<field name="name" string="Custom Name"/>
I tried this approach:
<field name="name" attrs="{'invisible': [('condition', '=', False)]}"/>
<field name="name" string="Custom Name" attrs="{'invisible': [('condition', '=', True)]}"/>
When condition changes, label also changes, but then the field stop working properly. I mean it only registers entered values for second field name
. If I change condition to False
, it does not show the value that was entered, like that would be new field, even though it is the same field, just one time it is with string
attribute, other without it.
You can only show each field in the form view once, as you found out. You only can use the following conditional attributes within the
attrs
attribute: