Is it possible to implement a conditional attribute on a field in Odoo?

Does anyone know if it is possible to implement a conditional attribute on a field?

For example:

<field name="name"/>

      

And if the condition is met:

<field name="name" string="Custom Name"/>

      

I've tried this approach:

<field name="name" attrs="{'invisible': [('condition', '=', False)]}"/>
<field name="name" string="Custom Name" attrs="{'invisible': [('condition', '=', True)]}"/>

      

When conditions change, the label also changes, but then the field stops working correctly. I mean it only logs the entered values ​​for the second field name

. If I change the condition to False

, it does not display the entered value as it would be a new field, even though it is the same field, only once with the attribute string

and another without it.

+3


source to share


3 answers


You can only show each field as a form once, as you learned. You can only use the following conditional attributes:



<field name="name" attrs="{'invisible': [('condition', '=', False)]}"/>
<field name="name2" attrs="{'readonly': [('condition', '=', False)]}"/>
<field name="name3" attrs="{'required': [('condition', '=', False)]}"/> 

      

+1


source


What you can do is add labels.

<div >
    <label for="name" attrs="{'invisible': [('condition','=',False)]}"/>
    <label for="name" string="Custom String" attrs="{'invisible': [('condition','=',True)]}"/>
</div>
<field name="name" nolabel="1" />

      



the only problem is that it will not have a vertical separator between the label and the field value.

+1


source


If that's all, to update a field label based on a condition, you should try fields_view_get.

0


source







All Articles