Date
Interface
export type IDateTypeValue = string | null;
export interface IDateField extends CommonField {
type: 'date';
options?: {
placeholder?: string;
format?: string;
};
private?: () => Promise<IDateTypeValue>;
render?: (v: IDateTypeValue) => JSX.Element;
validation?: Validation<IDateTypeValue>;
}Example
Basic Date Field
{
type: 'date',
name: 'YOUR_PATH',
}Email with placeholder and format
{
type: 'date',
name: 'YOUR_PATH',
options: {
placeholder: 'Enter your date',
format: 'yyyy-MM-dd'
},
validation: z
.string()
.refine(
(val) =>
!val ||
(new Date(val) instanceof Date &&
!isNaN(new Date(val).getTime()) &&
new Date(val) >= new Date('2024-01-01')),
{ message: 'Date must be after 2024-01-01 or empty' }
)
.or(z.literal(''))
}