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

Validate on blur only after the user has typed something or triggered change event #5712

Closed
vursen opened this issue Jul 11, 2023 · 5 comments
Labels
enhancement New feature or request validation

Comments

@vursen
Copy link
Contributor

vursen commented Jul 11, 2023

Describe your motivation

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:

Describe the solution you'd like

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.

@vursen
Copy link
Contributor Author

vursen commented 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:

  1. the user has typed something (to ensure that entering bad input will enable validation on blur).
  2. 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.

@vursen vursen 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 Jul 21, 2023
@vursen vursen 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 Jul 21, 2023
@tengcomplex
Copy link

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
Copy link
Contributor Author

vursen commented 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
Copy link
Contributor Author

vursen commented 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.

@vursen vursen closed this as completed Nov 14, 2023
@vursen vursen reopened this Nov 14, 2023
@vursen vursen transferred this issue from vaadin/web-components Nov 14, 2023
@yuriy-fix
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request validation
Projects
None yet
Development

No branches or pull requests

3 participants