vantezzen / auto-form

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

How to catch autoForm errors? #26

Closed JheanAntunes closed 10 months ago

JheanAntunes commented 10 months ago

I wanted to display the errors of the messages that I put in the validation in the schema, does anyone know how to do it ?

vantezzen commented 10 months ago

AutoForm uses shadcn's FormMessage component which should automatically show the error messages that zod throws.

If you want to manually add messages, you can use values and onValuesChange (https://github.com/vantezzen/auto-form/tree/main#controlled-form) to get the current values, pass them through zod yourself and use the renderParent(https://github.com/vantezzen/auto-form/tree/main#custom-parent-component) config to add error message elements next to the inputs.

JheanAntunes commented 9 months ago

Thank you, friend, for solving my question.