-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[v5] Remove condition restricting error display to touched inputs #9781
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fzaninotto
reviewed
Apr 18, 2024
adguernier
reviewed
Apr 18, 2024
adguernier
approved these changes
Apr 18, 2024
djhi
reviewed
Apr 18, 2024
docs/Upgrade.md
Outdated
Comment on lines
909
to
918
## Inputs No Longer Require To Be Touched To Display A Validation Error | ||
|
||
In previous versions, validation errors were only displayed after the input was touched or the form was submitted. In v5, validation errors are fully entrusted to the form library (`react-hook-form`), which is responsible to decide when to display them. | ||
|
||
For most use-cases this will have no impact, because `react-hook-form` works the same way (it will wait for an input to be touched before triggering its validation). | ||
|
||
But this should help with some advanced cases, for instance if some validation errors need to be displayed on untouched fields. | ||
|
||
It will also improve the user experience, as the form `isValid` state will be consistent with error messages displayed on inputs, regardless of whether they have been touched or not. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be useful to remind users of the mode
prop with a link to RHF documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
djhi
approved these changes
Apr 18, 2024
fzaninotto
approved these changes
Apr 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
All RA inputs have this condition:
which only allows to display validation errors if the input is touched or the form was submitted.
This prevents displaying errors preventively on inputs that have not been touched. Besides, it could be argued that it’s the form lib’s responsibility to decide what inputs are in error, and RA should not be opinionated about this.
Solution
Remove this check from all inputs.
Additional info
This will probably render #9724 obsolete.