-
I have created a sample. If you insert the following z.object() into the resolver, you will see that the console.log in refine() stops working. Is there some kind of rule for using resolver?
Maybe I'm using it wrong...? codeSandbox: https://codesandbox.io/s/jovial-colden-ew7l55?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
This behavior is not RHF induced, but rather the way Zod works. Check out Zod issue thread: colinhacks/zod#479
|
Beta Was this translation helpful? Give feedback.
-
@pcp-atobe : Your zod schema defines "NumberInput" as a mandatory field therefore when parsing and validating data by zod library, the target data is not valid and stops at validation phase instead of continuing to "refinement" phase. Switching "NumberInput" to optional will solve the issue. Working demo: https://codesandbox.io/s/nostalgic-sara-i01e94?file=/src/App.js:364-372 |
Beta Was this translation helpful? Give feedback.
-
Use partial : https://codesandbox.io/s/blissful-wright-33wc6w?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
-
If use I fixed to a new group for password. const reqBodyScheme = z
.object({
passwordGroup: z.object({
password: z.string().min(1, { message: "required" }),
passwordConfirm: z.string().min(1, { message: "required" })),
})
.refine(
(data) => {
console.log(data);
return data.password === data.passwordConfirm;
},
{
message: "Passwords don't match",
path: ["passwordConfirm"], }
}
),
NumberInput: z.number() // <- If you comment this out and use only z.string(), the refine works
});
; |
Beta Was this translation helpful? Give feedback.
@pcp-atobe : Your zod schema defines "NumberInput" as a mandatory field therefore when parsing and validating data by zod library, the target data is not valid and stops at validation phase instead of continuing to "refinement" phase.
Switching "NumberInput" to optional will solve the issue. Working demo: https://codesandbox.io/s/nostalgic-sara-i01e94?file=/src/App.js:364-372