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.