Is Valid is not turning to false if you settled an error imperatively
See original GitHub issueDescribe the bug
isValid attribute is not changing if you set an error imperatively if you previosly set a defaultSchema using yup.
Scenario:
Created a form instance using useForm
hook, following the requirements of this particular edge case:
- first name is required
- if a question is provided then an answer has to be provided
- if an answer is provided then a question has to be provided
To Reproduce
-
type something in the first name;
-
observe that the button that was disabled now it is enabled;
-
type an answer;
-
observe that the question has an error
Expected behavior isValid should be false, hence the button has to be disabled due to the errors object contains some errors in it.
Actual behavior isValid stays true, hence the button has to be enabled even though the error object contains some invalid fields to be validated.
Screenshots



Desktop (please complete the following information):
- OS: [iOS]
- Browser [chrome]
- Version [83.0.4103.61 (Official Build) (64-bit)]
Codesandbox link (Required) https://codesandbox.io/s/spring-pond-85dgq?file=/src/App.js
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
React Hook Form’s
formstate
isValid is driven by schema against formdata
(when not using the build-in validation). SosetError
is not going to be the solution, and we can’t make it work against validation schema result, because it will conflict the source of the truth.Since schema validation
isValid
is going to drive by schema result (or kind has to), at the same time I see your concern as well when an error is not associated with the form. a situation like this I can’t see any other workaround than callingtriggerValdiation()
to validate the entire form and manage errors message manually viadirty
&touched
formState, or you will have to useresolver
to write some custom logic.I hope the above gives you some more insight.
But you’re right, i guess that can handle some edge cases using validationResolver instead of validationSchema, i will try to migrate it and see how it works