Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose validate() method to allow developers to trigger validation manually #6634

Open
vursen opened this issue Sep 12, 2024 · 3 comments
Open

Comments

@vursen
Copy link
Contributor

vursen commented Sep 12, 2024

Describe your motivation

Field components lack an API to trigger their constraint validation manually. Manual triggering would be useful for example when you are building a simple form where you don't want to use Binder because constraint validation is sufficient, but you do want to validate the fields on a certain action like submit button click.

Having this API would also allow us to rewrite some docs examples to not use Binder, for example: https://vaadin.com/docs/latest/components/checkbox#required

Describe the solution you'd like

All field components already have a validate method that could be used for that purpose. It just needs to be made public.

Describe alternatives you've considered

The only available alternative at the moment is to use Binder because it provides a validate() method.

Additional context

@vursen
Copy link
Contributor Author

vursen commented Sep 12, 2024

Using the validate() method to manually validate fields managed by Binder may lead to a weird state, but that's probably fine to accept. This limitation could be mentioned in the JavaDoc of that method.

@yuriy-fix
Copy link
Contributor

We could proceed with this one, but would be preferable to have a clear documentation on how it affects the validation through Binder.

@vursen
Copy link
Contributor Author

vursen commented Oct 3, 2024

This would also enable us to add docs examples for required validation for RadioGroup and Select, similar to the Checkbox article after Binder usage is replaced with the validate method there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants