This question has been flagged
2 Replies
10828 Views

Good day Guys,

I have a field that is a Selection field e.g

type_main = fields.Selection(selection =([('a','A'),('b','B'),('c','C')]), 'Main Type')

but i want to dynamically show another field on the form view when either a, b or c is selected from the type_main field e.g i want that when you select A then a field that links to product.template module-(field.Many2one) is displayed, but if you select B then the displayed field is related to hr.employees-(field.Many2one) and finally selecting C displays a field that related to accounts.asset.asset (field.Many2one).

Any suggestions will be appreciated.

NB: Am using Odoo 8.


Thanks for your answers, it works now!. But i have the following issues with the solution

1) Am Using 

 widget="one2many_list"

to display the tree in another Model's view, all 3 fields field1, field2, field3 do not display inline, they all display at the bottom of the page when the corresponding type_main is selected, ie if i select Option A from type_main the field1 displays at the bottom of the page instead of in the tree view.. So my question is, is there a way to force a field display at a particular point on the page or at least correct this behaviour.

2) Also the label of the fields are always visible on the tree view from Q1, but i want them entirely hidden. I have tried to use 

<field name="field1" attrs="{'invisible': [('type_main', '!=', 'a')]}" nolabel="1"/>

but it still permanently displays on the tree view. Is there a way to remove its label from the tree view?

NB: I tried to use comments but i dont have required karma, sorry guys.

Avatar
Discard
Best Answer

Hello,

You have to write your fields with attrs as like below.

<field name="field1" attrs="{'invisible': [('type_main', '!=', 'a')]}"/>
<field name="field2" attrs="{'invisible': [('type_main', '!=', 'b')]}"/>
<field name="field3" attrs="{'invisible': [('type_main', '!=', 'c')]}"/>

According to above attrs when you select 'a' inside 'type_main' at that time 'field1' is visible, same as 'b' inside 'type_main' then 'field2' is visible and 'c' inside 'type_main' then 'field3' is visible.

I think you will get what you want.

Note : You have also make thoese fields 'required' using attrs as like invisible.

Avatar
Discard
Best Answer

This could be easily done using attrs on each of the many2one fields using the field type_main in a domain, like:


<field name="field1" attrs="{'invisible': [('type_main', '!=', 'a')]}"/>
<field name="field2" attrs="{'invisible': [('type_main', '!=', 'b')]}"/>
<field name="field3" attrs="{'invisible': [('type_main', '!=', 'c')]}"/>
Avatar
Discard

Here you have to put opeerator '!=' because it is for 'invisible' not for 'visible'. I think you get it.

Edited, thanks