robertLichtnow / zod-formik-adapter

An adapter for zod object validation to Formik validation schema
https://www.npmjs.com/package/zod-formik-adapter
MIT License
159 stars 15 forks source link

.array not working #22

Open yepes opened 1 year ago

yepes commented 1 year ago

Describe the bug Fields defined in zod as an array are not working with formik

To Reproduce Create a zod validator:

const zAsegurado = z.object({
  name: z.string(),
  nif: zodDni,
  email: z.string(),
});

const zFormSchema = z.object({
  numPoliza: z.string().min(3, { message: 'Minimo 3' }),
  nif: zodDni,
  email: z.string().email(),
  name: z.string().min(3, { message: 'Minimo 3' }),
  insured: z.array(zAsegurado),
});

And just use formik fieldArray for the insured property.

Expected behavior component should work out of the box

Zod, Formik and zod-formik-adapter versions:

Additional context The problem is that formik touched property would be an array containing objects. The errors of this library would be in the form of insured.nif, insured.1.nif and so on, so you will need a custom ErrorMessage for this to work

comxd commented 1 year ago

Have you tried with: insured: zAsegurado.array()?