Skip to Content
Menu
This question has been flagged
2 Replies
9980 Views


I am trying to update a context from onchange method. Below is code reference-

@api.onchange('country')
def country(self):
    """verify country."""

    self = self.with_context(flag = True)

@api.onchange('state')
def state(self):
    """verify state."""

    print self.env.context

When def country is called i am able to print flag=True in context But when def state method is called i m unable to get flag=True

Also below if my xml code to hide field using context

field name="productname" invisible="context.get('flag', True)"

But flag=True unable to locate under context!!

How i can fix it?


Avatar
Discard
Best Answer

Hi Shashank,

Context will not work in your case. 

You would need to create a new boolean field and set it's value from the onchange and use that boolean field to show / hide your other field.

Avatar
Discard

Hi Sudhir,

I tried your approach, but the boolean field is not updated in onchange method. Do I need a special flag for the boolean field like store=true or something?

By default normal fields are store=True. Please share your code you are working on.

Thank You , Sudhir sir.

Your answer very help full me +1

Author Best Answer

@ Sudhir : Thanx for your feedback.

I have more than 25 fields on form view and i have lots of rules/use cases based on which i have to hide multiple fields.

Example: If condition A is True show field1,2,3,7 and rest of fields hide

If condition B  is True show field1,,7 and rest of fields hide


Would be very difficult for me to add 25 boolean fields to show/hide based on different scenarios

Avatar
Discard

I agree with you but you would need to use field(s) to do that. You can use the context but it will give you the value of the context set in action.

Related Posts Replies Views Activity
1
Apr 24
1469
1
Dec 23
2736
2
Nov 22
2420
0
Nov 22
2737
0
Oct 22
1066