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

Zod optional field with default value become required #73

Open mil920 opened 5 months ago

mil920 commented 5 months ago

Hi, I don't kown why i have a optional field in my zod schema when i put a default value for edit action. My field become required but i don't want that because it's filled by my model value or empty, so why it's required ? Am i doing something wrong ? Thanks

LandSprutte commented 3 months ago

if you wanna apply defaults I tend to do the following:

const EditFormt = (props: {vessel: any}) => 
<AutoForm
      formSchema={vesselInsertSchema}
      onSubmit={onSubmit}
      values={props.vessel && vesselInsertSchema.parse(props.vessel)}
    />