Defer validation until submit is clicked #108
Answered
by
airjp73
Rocinante89
asked this question in
Q&A
-
I'm building a form using zod as a validator, everything is going great! But I have a requirement for the error labels to not display until submit is clicked. Is there any way to defer clientside validation until then? Or even to not validate the form if the fields are empty? My issue is that if I autofocus on an email input and the user clicks away without entering anything, then the validation triggers |
Beta Was this translation helpful? Give feedback.
Answered by
airjp73
May 14, 2022
Replies: 1 comment 2 replies
-
Hi! Sorry for the slow answer. You're looking for the validationBehavior option on useField(fieldName, {
validationBehavior: {
// Set initial and whenTouched to "onSubmit" and it won't validate until submit
initial: "onSubmit",
whenTouched: "onSubmit",
// If you want this behavior to change after submit, you can change that here
whenSubmitted: "onChange"
}
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Rocinante89
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! Sorry for the slow answer. You're looking for the validationBehavior option on
useField
. Usage would be like this: