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

I have a form and on save the python check code is run which throws a ValidationError.

@api.constrains('a', 'b')
def _check_a_and_b(self):
for record in self:
if not record.a and not record.b:
raise ValidationError(_('You have to specify at least a or b'))

If the ValidationError is triggered from the form save I want the form field 'a' to get the focus.

아바타
취소

A better idea would be to make the fields a and b as required fields. Upon save if both fields aren't filled, both would be highlighted in red.

작성자

The example checks that at least one of the two fields is filled in. I know that this could be solved with attrs=required...

But unfortunately the real use case is more complex than the simple example I provided and the condition in which an ValidationError is raised is not available on the client side.