This question has been flagged
1 Reply
6681 Views

I'd like to set a style to a field depending on the value of other field.

For example:

I have a field name (string) and a field is_company (boolean). If is_company is True, I want to set the width of the field name to 100%. If not, the width must be 48%.

If is_company:

<field name="name" placeholder='Name' />

else:

<field name="name" placeholder='Name' class='oe_inline' style='margin-right: 2%%; max-width: 48%% !important;' />

The only conditional kind of style I found by the moment is the color:

< ... colors="green: is_company == True;">

But now, this is not what I'm looking for.

Avatar
Discard
Best Answer

Hello Juan Formoso,

To add conditional style for a field or any property you can use CSS class as below

Step 1: Create custom style you want and add it in CSS file of your module. 

Please find code in comment. 

I hope it will be useful to you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

Step 2: Inherit contacts form as below

<record id="view_partner_form" model="ir.ui.view">
<field name="name">Partner form with custom style</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="attributes">
<attribute name="class">is_company == True ? custom-style-class</attribute>
</xpath>
</field>
</record>