Closed coffeedefi14 closed 4 weeks ago
Hi,
I had a scenario where I wanted to create an association through my form. In this case I have a Station
with one or moreAvailablity
-objects, When I create a new Availablity
I want the associated StationId in my insert schema.
I found a way to do this by using zods omit
. Removing it from the schema, removes it from the form.
e.g:
export const availabilityInsertSchema = z.object({
title: z.string(),
from: z.coerce.date(),
to: z.coerce.date(),
description: z.string(),
stationId: z.string(), <--- required, but not a part of the form.
});
export type AvailablityInsert = z.infer<typeof availabilityInsertSchema>;
async function onSubmit(values: Omit<AvailablityInsert, "stationId">) {
if (!stationId) return;
const res = await createNewAvailabilityForStation({
...values,
stationId,
});
}
}
<AutoForm
formSchema={availabilityInsertSchema.omit({
stationId: true,
})}
onSubmit={onSubmit}
...
/>
thanks
Hi, i am using the following config to disable the date field, but it's not working : fieldConfig={{ date: { inputProps:{ disabled:true}
},