You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Validate on blur only after the user has typed something or triggered change event #5712
One of the actions that currently trigger field component validation is blur (when the component loses focus).
This behavior has been repeatedly pointed out as undesired in the case of the initial interaction, when the user leaves the field without entering anything:
Change the default behavior to avoid validating on blur until the user has typed anything. Additionally, provide an option to revert the old behavior.
One way to implement that is to introduce a flag that would indicate whether the field is dirty. The field is considered dirty as soon as the user starts entering anything into it. This flag can be then used in blur handlers to determine whether the validation has to be run. Setting the flag initially to true would enforce the old behavior.
Note, for components like date-picker and similar, the flag may need to be updated on some other actions as well.
changed the title [-]Should not validate fields on blur until the user has typed anything[/-][+]Should not validate on blur until the user has typed anything[/+]on Jul 13, 2023
changed the title [-]Should not validate on blur until the user has typed anything[/-][+]Do not validate on blur until the user has typed anything[/+]on Jul 14, 2023
The proposal has been slightly clarified after an internal discussion. We've reached a consensus that the component should be marked as dirty in either of the following situations:
the user has typed something (to ensure that entering bad input will enable validation on blur).
the user has triggered a change event (to ensure that, for example, selecting a date in a DatePicker's dropdown will also enable validation on blur).
Note, for components that don't have an input element – such as CheckboxGroup, Select, etc – the change event will be the only trigger to make the component dirty. This implies that, for such components, the required validation will only occur when changing the value from non-empty to empty. For RadioGroup, it means that the required validation will never be triggered anymore (as radio buttons cannot be unchecked), unless the component is initially set as dirty.
changed the title [-]Do not validate on blur until the user has typed anything[/-][+]Validate on blur only after the user has typed something or has triggered change event[/+]on Jul 21, 2023
changed the title [-]Validate on blur only after the user has typed something or has triggered change event[/-][+]Validate on blur only after the user has typed something or triggered change event[/+]on Jul 21, 2023
The work on the solution proposed in this ticket has been paused because, after conducting further research, we've found a potentially better approach that would also help resolve several other validation issues. It's currently in the Github discussion stage: https://github.com/orgs/vaadin/discussions/4434. Your feedback would be greatly appreciated.
After more consideration, we've decided to treat "validation on blur" as a bug in Flow components caused by the new validation mechanism. Therefore, it will be only removed from the Flow components. The web components will continue to validate on blur as before. Follow #5537 for more details.
Closing this as resolved for flow components as a part of #5537. Fix should be available in 24.3.0-beta1. DateTimePicker behaviour will be tackled separately.
Activity
[-]Should not validate fields on blur until the user has typed anything[/-][+]Should not validate on blur until the user has typed anything[/+][-]Should not validate on blur until the user has typed anything[/-][+]Do not validate on blur until the user has typed anything[/+]vursen commentedon Jul 21, 2023
The proposal has been slightly clarified after an internal discussion. We've reached a consensus that the component should be marked as dirty in either of the following situations:
Note, for components that don't have an input element – such as CheckboxGroup, Select, etc – the change event will be the only trigger to make the component dirty. This implies that, for such components, the required validation will only occur when changing the value from non-empty to empty. For RadioGroup, it means that the required validation will never be triggered anymore (as radio buttons cannot be unchecked), unless the component is initially set as dirty.
[-]Do not validate on blur until the user has typed anything[/-][+]Validate on blur only after the user has typed something or has triggered change event[/+][-]Validate on blur only after the user has typed something or has triggered change event[/-][+]Validate on blur only after the user has typed something or triggered change event[/+]tengcomplex commentedon Sep 28, 2023
AFAICT, nice work of @vursen so far.
I wrote a related SO question. It seems however there are not many complaints about this validation behaviour, which suprises me a little bit.
Is there any estimation when the described solution might be available in a build?
vursen commentedon Sep 28, 2023
Hello, @tengcomplex!
The work on the solution proposed in this ticket has been paused because, after conducting further research, we've found a potentially better approach that would also help resolve several other validation issues. It's currently in the Github discussion stage: https://github.com/orgs/vaadin/discussions/4434. Your feedback would be greatly appreciated.
vursen commentedon Oct 12, 2023
After more consideration, we've decided to treat "validation on blur" as a bug in Flow components caused by the new validation mechanism. Therefore, it will be only removed from the Flow components. The web components will continue to validate on blur as before. Follow #5537 for more details.
yuriy-fix commentedon Dec 5, 2023
Closing this as resolved for flow components as a part of #5537. Fix should be available in
24.3.0-beta1.DateTimePickerbehaviour will be tackled separately.