You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using ZOD, react-hook-form, axios in a next js form. I am facing difficulty regarding how to add validation logic to a password, confirm-password field in my form
they are initially hidden by a boolean state value (this state can be toggled thus adding/removing the 2 password field to DOM)
if rendered, then they are first required && secondly they should be same naturally
consteditProfileSchema=z.object({//...password: z.string().min(8,{message: "min 8 chars required"}).optional().or(z.literal("")),confirmPassword: z.string().optional().or(z.literal("")),//...}).refine((data)=>data.password===data.confirmPassword,{message: "password do not match",path: ["confirmPassword"],});
What I did :
I made them optinal or string, then checked they are equal or not with refine.
But I still think why should ZOD validation be applied something that is not in DOM?
My problems:
if i am not making those fields optional, ZOD is not letting me submit the form (I wonder why ? I mean these two inputs not in DOM, so why validation applied to them ?)
The text was updated successfully, but these errors were encountered:
I am using ZOD, react-hook-form, axios in a next js form. I am facing difficulty regarding how to add validation logic to a password, confirm-password field in my form
ZOD schema:
What I did :
But I still think why should ZOD validation be applied something that is not in DOM?
My problems:
The text was updated successfully, but these errors were encountered: