Open thomasheeney opened 1 week ago
Hi, per the zod docs after you do .flatten() the field errors is an "object that groups all issues by key." Can you maybe provide a code snippet of what you are getting with ZSA in field errors vs what you are expecting to receive.
My input schema is as follows:
z.object({
form: z.object({
email: emailSchema, //..email('You must provide a valid email'),
password: z.string().min(1, 'Your password is required'),
twoFactorCode: z.string()
}),
turnstile: z.string().nullish(),
callbackUrl: z.string().optional()
})
Because I am passing the form as another zod object, the flattened response comes back as
"fieldErrors": {
"form": [
"A valid email address is required",
"Your password is required"
]
}
The deep nesting is removed by flattening.
Gotcha, thanks for sharing this. Is it possible to use the formatted errors in your case?
{isError && error.code === "INPUT_PARSE_ERROR" && (
<div>{error.formattedErrors.form?.email?._errors}</div>
)}
If these could be the keyed fieldErrors zod returns before flattening
I am not sure what you mean by this, can you reference the zod docs? Happy to see what we can do here but not seeing how to get field errors before flattening.
What about using shapeError? Would that help?
Using the errors object, the key "fieldErrors" is returned flattened (here).
If these could be the keyed fieldErrors zod returns before flattening, it would be more possible to display each error on the correct place.