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
Binder should always validate after field's internal validation #8242
Comments
To my understanding, this is only relevant in the case when a field component has a "default validator" which would always be used by Binder in addition to the user-configured validators. Rather than reacting to every blur event, it might be more appropriate to introduce a new event that is fired by components with a default validator whenever their internal validation status changes. |
I've changed the ticket title and description from "Binder should validate on blur" to be more generic, focusing on the problem and leaving the solution to be decided. |
👍 . Having |
#13940) (CP: 23.1) (#13993) Adds the needed API to notify Binder about validation status changes that happen in field components. Fixes #8242 Related to vaadin/flow-components#1158
This ticket/PR has been released with Vaadin 23.1.2. |
Currently
Binder
validates fields onValueChangeEvent
, because the valid/invalid -state is based only on the field's server-side value.However, some fields should be also validated when the field is blurred and only the presentation value has changed. For example, when entering "asdf" to an empty
DatePicker
, the server-side value remainsnull
, but the validation-state should change from valid to invalid. Same applies to eg. non-parseable numbers entered in number fields. This kind of validation should be implemented by the components themselves, butBinder
should also re-validate, so that all validators are effective.For more details, see: https://github.com/vaadin/vaadin-date-picker-flow/issues/223#issuecomment-623386532
Possible solutions:
Binder
validate also onblur
, if field implementsBlurNotifier
(although academically incorrect)HasValidator
fields to notifyBinder
that it should validateThis issue would be also good to get fixed: https://github.com/vaadin/flow/issues/8241
One more thing to consider is the inconsistency between Java and web component users:
The UX for web components has been designed so that "visiting" (focus and blur even without changing value) is considered "enough" to trigger validation (https://github.com/vaadin/vaadin-text-field-flow/issues/193#issuecomment-502631352).
Java forms and fields on the other hand validate only on value changes, which can mean many situations based on the
ValueChangeMode
, but it never means visiting a field without changing anything.This inconsistency might become more disturbing with Vaadin 15+, where a single application may contain views written in Java, and others created with TypeScript.
The text was updated successfully, but these errors were encountered: