Interactive demo of date picker field
/**
* Date Field Demo - Interactive examples of date picker fields
*/
import { Form, FormBuilder } from '@saastro/forms';
import { FormProvider } from '@/components/FormProvider';
import { TooltipProvider } from '@/components/ui/tooltip';
const config = FormBuilder.create('date-demo')
.layout('manual')
.columns(12)
.addField('birthdate', (f) =>
f
.type('date')
.label('Date of Birth')
.placeholder('Select your birth date')
.helperText('When were you born?')
.required('Date of birth is required')
.columns({ default: 12, md: 6 }),
)
.addField('appointment', (f) =>
f
.type('date')
.label('Appointment Date')
.placeholder('Select appointment date')
.helperText('Choose a date for your appointment')
.required()
.columns({ default: 12, md: 6 }),
)
.addField('deadline', (f) =>
f
.type('date')
.label('Project Deadline')
.placeholder('Select deadline')
.helperText('When should this be completed?')
.optional()
.columns({ default: 12 }),
)
.addStep('main', ['birthdate', 'appointment', 'deadline'])
.build();
export default function DateDemo() {
const handleSubmit = (data: Record<string, unknown>) => {
console.log('Form submitted:', data);
alert('Form submitted! Check console for data.');
};
return (
<TooltipProvider>
<FormProvider>
<Form config={config} onSubmit={handleSubmit} className="space-y-4" />
</FormProvider>
</TooltipProvider>
);
} Overview
The date picker field provides a calendar interface for selecting dates. It supports date constraints, disabled dates, and integrates with react-day-picker.
Usage
Basic Date Picker
import { FormBuilder } from '@saastro/forms';
const config = FormBuilder.create('form')
.addField('birthdate', (f) =>
f
.type('date')
.label('Date of Birth')
.placeholder('Select your birth date')
.required('Date of birth is required'),
)
.addStep('main', ['birthdate'])
.build();
With Date Constraints
.addField('appointment', (f) =>
f.type('date')
.label('Appointment Date')
.placeholder('Select a date')
// Future dates only (via Zod)
.schema(z.date().min(new Date(), 'Must be a future date'))
.required()
)
Default Value
.addField('startDate', (f) =>
f.type('date')
.label('Start Date')
.value(new Date())
.required()
)
JSON Configuration
{
"type": "date",
"label": "Date of Birth",
"placeholder": "Select your birth date",
"schema": { "required": true }
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
type | 'date' | - | Field type (required) |
label | string | - | Label text |
placeholder | string | - | Placeholder text |
helperText | string | - | Help text below field |
value | Date | - | Default date |
columns | Partial<Record<Breakpoint, number>> | - | Grid columns by breakpoint |
disabled | boolean | function | ConditionGroup | false | Disable the field |
hidden | boolean | function | ConditionGroup | Responsive | false | Hide the field |
Validation
Required Date
.addField('eventDate', (f) =>
f.type('date')
.label('Event Date')
.required('Please select a date')
)
With Zod Constraints
import { z } from 'zod';
.addField('deadline', (f) =>
f.type('date')
.label('Deadline')
.schema(z.date()
.min(new Date(), 'Must be a future date')
.max(new Date('2025-12-31'), 'Must be before end of 2025')
)
)
Styling
Custom Classes
.addField('birthdate', (f) =>
f.type('date')
.label('Date of Birth')
.required()
.classNames({
wrapper: 'bg-muted/30 p-4 rounded-lg',
input: 'border-2 border-primary/20',
label: 'text-lg font-semibold',
error: 'text-destructive text-sm',
})
)
Responsive Layout
.addField('eventDate', (f) =>
f.type('date')
.label('Event Date')
.columns({ default: 12, md: 6 })
)
JSON Styling
{
"type": "date",
"label": "Date of Birth",
"wrapper_className": "bg-muted/30 p-4 rounded-lg",
"input_className": "border-2 border-primary/20",
"label_className": "text-lg font-semibold",
"columns": { "default": 12, "md": 6 }
}
Related Fields
- Date Range - Select a range of dates
Accessibility
- Built on react-day-picker
- Full keyboard navigation
- Screen reader support
- ARIA labels for calendar navigation