Autoform fields with one to many relation

Hello everyone,

I am using Wrapper around Autoform. i have custom form layout, with custom fields, and those custom fields are mapped to autoforms field.

I have many forms which have nested objects. For example, a project with multiple stories, each story have multiple type of tasks. Need to have validation as well if task is completed, enter a date time when it is completed.

In general, how should we handle such scenarios?

Thank you

For client-side validation, you can add custom validation logic using the validators property in the fieldOptions, as described here: https://vaadin.com/docs/latest/components/auto-form#validation. In this validation logic, you should be able to access nested objects and fields of your business objects, like project.stories[0].tasks[0].dateOfComplition etc.

For server-side validation, which is always the better option for sensitive validation, you could define your own Bean Validators as described here: https://vaadin.com/docs/latest/hilla/guides/forms/binder-validation#defining-custom-constraints. Hilla’s AutoForm will consider this custom validators, when you use it as annotation in the entity that belongs to the AutoForm.

2 Likes