You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a base interface for a form, but each of my pages extends that to create an extended form. Now I want to create a child component that generates a form based on the extended template.
Type 'T' is not assignable to type 'AsyncDefaultValues<T> | DefaultValues<T> | undefined'.
Type 'IProductSourceBase' is not assignable to type 'AsyncDefaultValues<T> | DefaultValues<T> | undefined'.
Type 'IProductSourceBase' is not assignable to type 'DefaultValues<T>'.ts(2322)
If I remove the default values completely none of the names are recognised when I want to create form elements.
What I want is for my parent component to create productBaseSchema.extend({}) which is a z.ZodObject<{}> and then pass this extended schema to the child const extendedSchema: z.ZodObject<z.objectUtil.extendShape<{}> that can also give onSubmit, render functions in its props so only parent only deals with extra fields.
Examples:
export interface IProductSourceBase {
productId: string;
sourceId: number;
sourceMeta?: any;
}
const productSourceBaseSchema = z.object({
productId: z.string().nonempty(translate("Product ID is required")),
sourceId: z.coerce.number().int(translate("Source ID must be an integer")).gt(0, translate("A source must be selected")),
});
const extendedSchema = productSourceBaseSchema.extend({
sourceMeta: z.object({
sourceUrl: z.string().url(translate("This is not a valid URL")).nonempty(translate("Url is required")).refine(
(url) => /\/spreadsheets\/d\/([a-zA-Z0-9-_]{16,44})/.test(url), // Test for valid Spreadsheet ID
{
message: translate("This is not a valid Google Spreadsheet ID"), // Custom error message
}
),
cell: z.string().nonempty(translate("Cell number is required")).refine(
(cell) => /^[A-Za-z]+[1-9]\d*$/.test(cell), // Check if the cell matches the pattern
{
message: translate("Invalid cell reference format"), // Custom error message for invalid format
}
),
}),
});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a base interface for a form, but each of my pages extends that to create an extended form. Now I want to create a child component that generates a form based on the extended template.
https://github.com/amunim/use-form-template-example
but it gives this error on defaultValues
If I remove the default values completely none of the names are recognised when I want to create form elements.
What I want is for my parent component to create
productBaseSchema.extend({})
which is az.ZodObject<{}>
and then pass this extended schema to the childconst extendedSchema: z.ZodObject<z.objectUtil.extendShape<{}>
that can also give onSubmit, render functions in its props so only parent only deals with extra fields.Examples:
Beta Was this translation helpful? Give feedback.
All reactions