Skip to content

updateForm : improve relations support #34

@damienroche

Description

@damienroche

Clear and concise description of the problem

Considering the following scenario :

export interface Vehicle {
   id: number
   name: string
}

export interface Itinerary {
   id: number
   vehicle: Vehicle 
   label: string
}
const updateFormSchema = z.object({
   vehicle: z.number(),
   label: z.string()
})

export default defineItemType<Itinerary>().model({
   name: 'itineraries',
   formSchema: {
      update: updateFormSchema
   }
})

when I want to create an updateSchema :

const itineraryForm = await store.itineraries.updateForm(props.id)

itineraryForm.vehicle is an objet of type Vehicle. But in my case I would like to have his id.
I have try with pass defaultValues to overrides this, but it don't work.

Suggested solution

We can imagine to pass the data to the defaultValues function to map model within the form

const itineraryForm = await store.itineraries.updateForm(props.id, {
   defaultValues: (item) => ({
      ...item,
      vehicle: item.vehicle.id
   }
})

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions