コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
11057 ビュー


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?


アバター
破棄
最善の回答

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.

アバター
破棄

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

著作者 最善の回答

@ 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

アバター
破棄

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.

関連投稿 返信 ビュー 活動
2
1月 25
6813
1
1月 25
1468
1
4月 24
2797
1
12月 23
5025
2
11月 22
4154