콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
11043 화면


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
6794
1
1월 25
1450
computed fields 해결 완료
1
4월 24
2782
1
12월 23
4991
2
11월 22
4132