Table - row Validation

I have a Table row with some checkbox fields.
When checkbox 1 is checked then checkbox 2 mastn’t be checked and vice versa.
(there are some more such condition). If all conditions are met, then the data-row is ok.

See Attachment: only one field in each column group (different colors) may be selected.
If more fields are selected, the data (for the row) are wrong.

How can I do this in Vaadin?



Cross-field validation is something we still haven’t tackled properly in my opinion. For now, I’m afraid you have to create those validators yourself. For each validation case, you need to create a custom validator (in this case the validator needs both checkboxes as arguments). For each row, create one validator object, and add it to both affected fields. Remember to set the fields to immediate as well.

Then the tricky part; when the user changes the value in one checkbox, its validator will be run automatically. If validation fails, that field will get the error you give; but the other field won’t (since Vaadin didn’t know you validated the value of both). So, in your validator, you need to set the error manually for both fields, and not throw an exception (so that Vaadin won’t interfere). A hacky solution to be sure; but it also gives you full control over how to display the actual error.

Hope that helps :slight_smile: