Replies: 3 comments 1 reply
-
You can pass the const handleSetMockEmail = () => {
setValue(
"email",
"[email protected]",
+ { shouldValidate: true }
)
} |
Beta Was this translation helpful? Give feedback.
-
@Moshyfawn thanks for the quick response, i didn't know that option. is there a way to do that? |
Beta Was this translation helpful? Give feedback.
-
You can get reference to the const { formState } = useForm()
const { isSubmitted } = formState
const handleSetMockEmail = () => {
setValue(
"email",
"[email protected]",
{ shouldValidate: isSubmitted }
)
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Version Number
7.45.4
Codesandbox Example
https://codesandbox.io/s/react-hook-form-with-yup-forked-kgxsfn?file=/src/App.js
Steps to reproduce
Expected behaviour
calling setValue('fieldName', 'some data'), should not be outside of form sync,
thus, in this case, it should change the errors / dirty states of the email field,
exactly like a user input would do.
if not, I guess there must be another way to make the form data in sync after calling setValue.
(trigger() / onSubmit(() => {})() are not good options, because for example, if calling setValue before the user submitted the form, I don't want to show error messages yet)
What browsers are you seeing the problem on?
Chrome
Relevant log output
logs of values and errors after each reproducing steps:
1.
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions