vantezzen / auto-form

🌟 A React component that automatically creates a @shadcn/ui form based on a zod schema.
https://vantezzen.github.io/auto-form/
MIT License
2.75k stars 99 forks source link

required_error message never shows #39

Closed johann-taberlet closed 11 months ago

johann-taberlet commented 11 months ago

First, thanks for this project.

I don't know if I'm doing something wrong but the required_error message is never shown for me. Native browser error does.

const formSchema = z.object({
        email: z.
            string({
                required_error: "Veuillez renseigner votre e-mail.",
            })
            .email({
                message: "E-mail incorrect.",
            })
    });

iScreen Shoter - Google Chrome - 231016002710

Am I doing something wrong ?

Email format check error works as intended and display the red message.

vantezzen commented 11 months ago

This is expected behavior: The native errors validate before the zod validations are made. So if the native validation fails it will not get to zod - only if native validation passes.

If you want, you can remove the native validation code to only show zod errors.

johann-taberlet commented 11 months ago

Thanks, I just found the answer (which was actually in the question).

Adding formNoValidate on the submit button indeed solved that issue.