Odoo Help

1

Dynamically display fields based on fields.Selection() options

By
Nnamdi Jibunoh
on 1/28/16, 4:53 PM 1,564 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.

0

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.

0
Axel Mendoza
On 1/28/16, 5:25 PM

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')]}"/>

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

Emipro Technologies Pvt. Ltd.
on 1/29/16, 12:40 AM

Edited, thanks

Axel Mendoza
on 1/29/16, 1:22 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/28/16, 4:53 PM
Seen: 1564 times
Last updated: 1/29/16, 3:22 AM