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
// set global error mapz.setErrorMap((issue,ctx)=>{letmessage: string;switch(issue.code){casez.ZodIssueCode.invalid_type:
if(issue.received===z.ZodParsedType.undefined){message=`${issue.path.at(-1)} is required`;}break;// ... other cases}return{ message }})
if i parse {confirmPassword: undefined}, the error message looks like this:
confirmPassword is required
but what i want the error message like this:
Confirm Password is required
is there something like issue.name that i can use to pass it to the error message? maybe something like this for the schema to declare custom input name/path?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
is there any way to give name to each input in the schema?
I'm creating a zod error map where i want to include the input name in the error message. currently i'm using the issue path.
example:
if i parse
{confirmPassword: undefined}
, the error message looks like this:but what i want the error message like this:
is there something like
issue.name
that i can use to pass it to the error message? maybe something like this for the schema to declare custom input name/path?Beta Was this translation helpful? Give feedback.
All reactions