Revalidate onChange after Trigger call #2444
-
Hi! Thank you guys for all the work you've put into this library – I've been very impressed with all the features so far! Right now it seems that if |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
can you explain that in a codesandbox? |
Beta Was this translation helpful? Give feedback.
-
Hi! Really apologize for the late reply! Here is a fork of the trigger example code but removing some extraneous components: https://codesandbox.io/s/react-hook-form-v6-triggervalidation-b77uy?file=/src/index.js:0-61 After clicking the |
Beta Was this translation helpful? Give feedback.
-
You can submit your form with handleSubmit() instead of using trigger(). That way the revalidation will work and all you have to do is to block the first submit so you don't submit prematurely. |
Beta Was this translation helpful? Give feedback.
-
Hi, for more infor: check the doc https://www.react-hook-form.com/api/useform/#mode |
Beta Was this translation helpful? Give feedback.
-
Instead of
What do you think? |
Beta Was this translation helpful? Give feedback.
-
handleSubmit should not work here. But I think it can be solved easily with
Now setMode to onChange when you are triggering like following- const isValid = await trigger(undefined, { shouldFocus: true });
if (isValid) {
// Do something here
setMode("onSubmit") // Change validation mode to onSubmit(To Default one)
} else {
setMode("onChange") // If not valid change the mode to onChange
} |
Beta Was this translation helpful? Give feedback.
Hi! Really apologize for the late reply! Here is a fork of the trigger example code but removing some extraneous components: https://codesandbox.io/s/react-hook-form-v6-triggervalidation-b77uy?file=/src/index.js:0-61
After clicking the
Validate All
button, any fields with missing input will continue to show an error state even after typing values in them. Is it possible for validation to runonChange
after a programmatictrigger
call?