How to use attrs attribute on Odoo to combine multiple attributes (invisible, readonly or required) into a single one?

21,256

Just remove the } symbol. I think that's your mistake

<field name="name" attrs="{'invisible': [('condition1', '=', False)], 'required': [('condition2', '=', True)]}"/>
Share:
21,256
RobbeM
Author by

RobbeM

Updated on February 20, 2020

Comments

  • RobbeM
    RobbeM over 4 years

    In Odoo when you have an xpath you can add "attrs" to a field like required or invisible, when a condition is met. This works fine.

    I'm trying to combine those 2. I can't get it to work and can't find anywhere how to do it.

    For example this is possible:

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

    But what I can't get to work is something like:

    <field name="name" attrs="{'invisible': [('condition1', '=', False)]}, 'required': [('condition2', '=', True)]}"/>
    

    I want one field to be invisible when condition 1 is met and (also) required when condition 2 is met. I've tried different syntaxes but don't know how to do it.

    What is the correct way to do it?