This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
issue: Validation issue after unmounting fields #11802
Comments
not clear on what's reported here. |
did you see the codesandbox and see that validation is not working as expected in the second form? i.e. validation is only being applied to the first input in the second form, when it should validate all fields. This happens when the form is unmounted when isSubmitting is set to true. If this is expected then nothing needs to be fixed. |
it wouldn't, rhf focus on single field validation at a time by design. if you need multiple use |
Hi @KaranLala , In your if (isSubmitting) return <div>Loading...</div>; as soon as you click the submit button this sets as true which unmount other elements but validations are still in process for other form field. when the You can try this way if you want all error message to be appeared let {
control,
handleSubmit,
formState: { errors, isSubmitting },
} = useForm({ criteriaMode: "all" }); |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Version Number
7.51.3
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/react-hook-form-7-51-3-validation-bug-z7yz34?file=%2Fsrc%2Fvalidation-not-working.js
Steps to reproduce
Expected behaviour
Not sure if it is expected or not, but its an easy trap to fall into. IMO isSubmitting should be true after validation. If this is as expected, a note about this in docs, or a new state that can be used to safely unmount the form during asynchronous operations would be helpful.
Using isValid && isSubmitting together seems to do the trick.
What browsers are you seeing the problem on?
No response
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: