Date
The date input type is used for date and datetime selection. It provides a calendar picker interface and supports both date-only and datetime formats.
Properties
Required Properties
- name (string): Unique identifier for the field
- type (string): Must be 'date'
- label (string): Display label for the field
Optional Properties
- placeholder (string): Hint text shown when field is empty
- disabled (boolean): Whether the field is disabled
- clearable (boolean): Whether the field can be cleared (default: true)
- now (boolean): Set current date as default value
- editable (boolean): Allow manual text input (default: true)
- time (boolean): Include time selection (default: false)
- isInfinity (boolean): Show infinity option for date ranges
- layout (string): Layout type (default, horizontal)
- rules (array): Validation rules for the field
Examples
Basic Date Field
typescript
{
name: 'birthDate',
type: 'date',
label: 'Birth Date',
placeholder: 'Select birth date',
rules: ['required']
}
Date with Time
typescript
{
name: 'meetingTime',
type: 'date',
label: 'Meeting Time',
placeholder: 'Select meeting date and time',
time: true,
rules: ['required']
}
Date with Default Value (Today)
typescript
{
name: 'startDate',
type: 'date',
label: 'Start Date',
placeholder: 'Select start date',
now: true,
rules: ['required']
}
Validation Rules
Common Date Validation Patterns
typescript
// Future date only
{
type: 'custom',
function: '(value) => new Date(value) >= new Date()',
message: 'Date must be in the future'
}
// Past date only
{
type: 'custom',
function: '(value) => new Date(value) <= new Date()',
message: 'Date must be in the past'
}
// Date range validation
{
type: 'custom',
function: '(value, formValues) => new Date(value) >= new Date(formValues.startDate)',
message: 'Date must be after start date'
}
// Age validation (18+ years)
{
type: 'custom',
function: '(value) => {
const birthDate = new Date(value);
const today = new Date();
const age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
return age > 18 || (age === 18 && monthDiff >= 0);
}',
message: 'Must be at least 18 years old'
}
Best Practices
- Use appropriate placeholders that guide user input format
- Set reasonable default values with the
now
property when appropriate - Enable time selection for scheduling and appointment forms
- Implement proper validation for date ranges and business logic
- Consider timezone handling for international applications
- Use clear labels that indicate the expected date format
- Test edge cases like leap years, month boundaries, and invalid dates
- Provide helpful error messages for validation failures
- Consider accessibility with proper ARIA labels and keyboard navigation
- Use consistent date formats across your application