Set error for multiple inputs with react-hook-form and zod #9772
Unanswered
kendall-wahnschaffe
asked this question in
General
Replies: 2 comments 3 replies
-
Pure Zod If I nest const schema = z
.object({
email: z.string().email(),
confirmEmail: z.string().email()
})
.refine((schema) => schema.email === schema.confirmEmail, {
message: "Emails do not match",
path: ["confirmEmail"]
})
.refine((schema) => schema.email === schema.confirmEmail, {
message: "Emails do not match",
path: ["email"]
})
console.log(
x.safeParse({
email: 'a@a.com',
confirmEmail: 'z@z.com'
})
.error.format()
) |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can use Working demo: https://codesandbox.io/s/react-hook-form-zod-resolver-example-forked-7dqt96?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
All I want to do is surface the same error to multiple inputs (so both inputs now have the
"Emails do not match"
text beneath and go away once the fields are valid. Is this possible?https://codesandbox.io/s/react-hook-form-zod-resolver-example-forked-60l55y?file=/src/App.js:176-933
Beta Was this translation helpful? Give feedback.
All reactions