issue: Zod refine error with objects #12188
Replies: 7 comments 4 replies
-
I've stumbled upon this same issue. In my case, I'm using const form = useForm({
resolver: async (data, context, options) => {
const result = await zodResolver(schema)(data, context, options)
console.log(result)
return await zodResolver(schema)(data, context, options)
},
defaultValues,
mode: 'onChange',
reValidateMode: 'onChange',
}) |
Beta Was this translation helpful? Give feedback.
-
Could you run this code snippet to check out the root cause?
|
Beta Was this translation helpful? Give feedback.
-
Please, reopen this issue, because looks like it's bug. |
Beta Was this translation helpful? Give feedback.
-
I have the same issue, but with |
Beta Was this translation helpful? Give feedback.
-
+1, having the same issue :/ |
Beta Was this translation helpful? Give feedback.
-
I validated that this issue can no longer be reproduced in v4.0.0 of the Here's my repro: https://github.com/jeknom/react-hook-form-zod-refine-issue-repro |
Beta Was this translation helpful? Give feedback.
-
I have the same issue and tested with the last updated packages at this time(RHF v7.55.0 and resolvers v5.0.0), sadly for some reason the error object is not being updated while the schema refine function is working well. |
Beta Was this translation helpful? Give feedback.
-
Version Number
7.52.1
Codesandbox/Expo snack
https://stackblitz.com/edit/vitejs-vite-a9bup4?file=src%2FApp.tsx
Steps to reproduce
I’m trying to validate if the min value is greater than the max value using Zod with a refine method.
But even when the min/max received invalid values (min: 99, max: 1) the RHF doesn’t fill the
error
object with error defined in the Zod refine method. TheisValid
property is set correctly to false.Notice that the
refine()
error is working fine for the fieldname
if I type something different thenabc
.The issue seems related when I have fields
min
andmax
defined inside an objectarea
.Using the Codesanbox from this topic:
abc
in the name field.99
for the min field.1
for the max field.error
object is empty.Expected behaviour
error
object should contain the error message defined in therefine()
zod method.What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions