Hanggi Anggono
Hanggi Anggono

Reputation: 31

Create Radio Button condition in Odoo 9

I'm new learning about odoo.

I have a module with two class, and in my XML, i just wanna make a radio button for part of the class, for example on individual and company radio button, I want to make radio button with a different button which shows different fields from two class.

Image

Thank You.

Upvotes: 2

Views: 5594

Answers (1)

jo541
jo541

Reputation: 1155

To do this, You must create a field Selection. In the XML of this field, you specify the widget radio button.

After for each field that is to be displaying in the view, you must add an attribute on the xml field to hide or display the value.

Example :

Python file

type = field.Selection(string='Type',selection=selection=[('val1', 'Val1'), ('val2', 'Val2')])
field1 = fields.Char(string='Field1')
field2 = fields.Char(string='Field2')

Xml file

<field name="type" widget="radio"/>
<field name="field1" attrs="{'invisible': [('type','=', 'val1'))]}"/>
<field name="field2" attrs="{'invisible': [('type','=', 'val2'))]}"/>

In this example, if the radio button has the value "val1" only the field1 is displaying. And if the radio button has the value 'val2' only the field2 is displaying.

Upvotes: 1

Related Questions