ui icon indicating copy to clipboard operation
ui copied to clipboard

Textarea + Form not throwing validation errors

Open zeevo opened this issue 2 years ago • 1 comments

Hello

I think the example on the docs does not work as intended.

I would expect it to show an error when the typing a value that breaches the zod schema but it does not.

Recreation sandbox here

Thanks for the all the great components

zeevo avatar Jun 29 '23 02:06 zeevo

Hi @zeevo, by default the useForm hook by react-hook-form has the mode set to onSubmit, this mean that the validation is applied only when the form is submitted. You can change it to onChange to get the behaviour you're expecting.

const form = useForm<z.infer<typeof FormSchema>>({
    resolver: zodResolver(FormSchema),
    mode: `onChange`
  })

For further information check the react-hook-form docs

dan5py avatar Jun 29 '23 08:06 dan5py

Thanks for the tip @dan5py !

zeevo avatar Jun 30 '23 22:06 zeevo