Reputation: 71
How can I use the onchange event in a many2one field to add/remove a page in notebook dynamically, I have tried using the function fields_view_get
but only runs when loading the view not on the onchange event.
Upvotes: 1
Views: 2523
Reputation: 9670
You can create a related field and write the right condition in the attrs
attribute in the page.
related_field = fields.Char(
string='Related field',
related='many2one_id.name',
store=False,
)
<field name="related_field" invisible="1" />
<page string="Title" attrs="{'invisible': [('related_field','=','Element name')]}">
...
</page>
Or if you condition is more complex you can use an onchange function like this
field_name = fields.Char(
string='Field name',
)
@api.one
@api.onchange('many2one_id')
def onchange_many2one_id(self):
# [...]
self.field_name = 'hidden'
But you need an attrs
attribute in the view as well
<field name="field_name" invisible="1" />
<page string="Title" attrs="{'invisible': [('field_name','=', 'hidden')]}">
...
</page>
I think you can develop what you want with these advices.
Upvotes: 1