-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when using zod-i18n-map
, field errors are [undefined]
#455
Comments
zod-i18n-map
, errors are undefined
zod-i18n-map
, field errors are [undefined]
There is an |
Ok, but how do I use it with Here's what i tried: // schemas.ts
import i18next from 'i18next';
import { z } from 'zod';
import translation from 'zod-i18n-map/locales/es/zod.json';
i18next.init({
lng: 'es',
resources: {
es: { zod: translation }
}
});
export const schema = z.object({
name: z.string().min(2),
email: z.string().email()
}); // some +page.server.ts file
import type { PageServerLoad } from './$types';
import { zodI18nMap } from 'zod-i18n-map';
export const load = (async () => {
const form = await superValidate(
zod(itemSchema, {
errorMap: zodI18nMap
})
);
return {
form
};
}) satisfies PageServerLoad; With the setup above, errors are still I also tried to set the error map both globally (with |
See if you can make a MRE at https://sveltelab.dev/github.com/ciscoheat/superforms-examples/tree/zod and I'll take a look. |
link to a MRE. See that in Also, in |
Even after following the instructions at https://github.com/aiji42/zod-i18n, I can't get safeParse (used directly on the schema) to show localized errors, unfortunately. Can you link to a working example for that? |
just found out the weirdest thing: first, i figured that the problem is with however, i was sure that (at some point) i was able to get it to work, but didnt know how conclusion: if the page that is importing the schema is SSR'd, it wont work (meaning the errors will be an array with a single undefined value). however, if the page is not SSR'd, it will work correctly (translated messages will show up just fine) im going to close the issue as it's unrelated to your package, sorry for the disturbance |
Description
When using
zod-i18n-map
, errors are undefined.if i have a schema defined as follows:
It works as expected, when sending a
name
with less than 3 characters, the error is displayed correctly.However, if it is defined as follows (see the
zod-i18n-map
docs):When sending a
name
with less then 3 characters, the form object has the following shape:If applicable, a MRE
SvelteLab link to a MRE
If the link is not working, you can just grab the template and set the
routes/schema.ts
file content as follows:To see the bug happen, click to submit the form and look at the terminal to see the form shape.
Additional information
At first i thought it was some sort of error in
zod-i18n-map
itself, but i tried.safeParse()
directly from the schema and the error messages are displayed correctly (in the configured language)The text was updated successfully, but these errors were encountered: