3

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?

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
RobbeM
  • 727
  • 7
  • 16
  • 36

1 Answers1

9

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

<field name="name" attrs="{'invisible': [('condition1', '=', False)], 'required': [('condition2', '=', True)]}"/>
ChesuCR
  • 9,352
  • 5
  • 51
  • 114
  • Can I use the syntax as condition1.type1 and condition2.type1 ? if condition1.type1 has the type1 attribute? – Akira Chen Sep 04 '20 at 02:04
  • @akira I don't think you can use dot notation there. You can always create related fields and use them in the domains – ChesuCR Sep 04 '20 at 11:17