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.27k stars 81 forks source link

Added support for nested array fieldConfig #53

Closed cipriancaba closed 7 months ago

cipriancaba commented 7 months ago

This should work now by passing the filedConfig to the AutoFormArray

const formSchema = z.object({
      title: z.string(),
      agendaItems: z
        .array(
          // Define the fields for each item
            z.object({
              name: z.string(),
              age: z.coerce.number(),
            }),
        )
        .describe('Agenda items'),
    })

<AutoForm
  formSchema={formSchema}
  fieldConfig={{
    agendaItems: { // <--------------------- HERE
      name: {
        fieldType: 'textarea',
        description: 'Name textarea', 
      },
    },
  }}
  onSubmit={(values) => {

  }}
>

      <AutoFormSubmit>Save</AutoFormSubmit>

</AutoForm>