Date Field Type
Description:
The date
field type is used to capture date and time information from users. It supports various date formats, timezone handling, and provides flexible input and export options. This field ensures that date and time data is captured consistently and can be used for scheduling, tracking, and temporal analysis within your application.
Elasticsearch Mapping: date
(format: dateOptionalTime
)
YAML Definition
- name: date_of_birth
type: date
display_name: "Date of Birth"
guidance: "Enter the date of birth."
required: true
readonly: false
hidden: false
default_value: ""
time_format: ""
input_format: ""
input_timezone: ""
export_format: ""
export_timezone: ""
validation: ""
validation_message: ""
Attributes
-
name (string): Required.
The unique identifier for the field. -
type (string): Required.
Must be set todate
for date fields. -
display_name (string): Optional.
The label displayed in the user interface. If not provided, a formatted version ofname
is used. -
guidance (string): Optional.
Help text or instructions for the field, assisting users in understanding what data to enter. -
required (boolean): Optional.
Iftrue
, the field must be filled before submission. Default:false
. -
readonly (boolean): Optional.
Iftrue
, the field is read-only and cannot be edited by the user. Default:false
. -
hidden (boolean): Optional.
Iftrue
, the field is hidden from the user interface. Default:false
. -
default_value (string): Optional.
The default date value displayed when the form is first loaded (ISO format). -
time_format (string): Optional.
Time format specification for displaying time components. -
input_format (string): Optional.
Input format for date entry by users. -
input_timezone (string): Optional.
Timezone for input processing. -
export_format (string): Optional.
Format specification for data export. -
export_timezone (string): Optional.
Timezone for export processing. -
validation (string): Optional.
Validation rules for the date field. -
validation_message (string): Optional.
Custom validation error message to display when validation fails.
Examples
Basic Date Field:
- name: date_of_birth
type: date
display_name: "Date of Birth"
required: true
guidance: "Enter the date of birth"
Date with Time:
- name: appointment_time
type: date
display_name: "Appointment Time"
time_format: "HH:mm"
input_format: "YYYY-MM-DD HH:mm"
input_timezone: "UTC"
required: true
Date with Export Formatting:
- name: created_date
type: date
display_name: "Created Date"
export_format: "MM/DD/YYYY"
export_timezone: "America/New_York"
readonly: true
Date with Validation:
- name: start_date
type: date
display_name: "Start Date"
validation: "min:today"
validation_message: "Start date must be today or in the future"
required: true
Usage Notes
- Date Formats:
- The field supports various date formats for input and display.
- Common format patterns include:
YYYY-MM-DD
: ISO date formatMM/DD/YYYY
: US date formatDD/MM/YYYY
: European date formatYYYY-MM-DD HH:mm
: Date with time
- Time Handling:
- Use
time_format
to specify how time components are displayed. - Use
input_format
to define the expected input format from users.
- Use
- Timezone Support:
input_timezone
: Specifies the timezone for input processing.export_timezone
: Specifies the timezone for export operations.- Common timezone values include
UTC
,America/New_York
,Europe/London
, etc.
- Validation:
- Use the
validation
attribute to enforce date constraints. - Common validation rules include:
"min:today"
: Date must be today or in the future."max:today"
: Date must be today or in the past."range:2024-01-01,2024-12-31"
: Date must be within a specific range.
- Use the
- Default Values:
- Use
default_value
to pre-fill the field with a default date. - Default values should be in ISO format (
YYYY-MM-DD
orYYYY-MM-DD HH:mm
).
- Use
- Readonly Fields:
- Use
readonly
for system-generated dates like creation timestamps. - Readonly date fields are typically calculated or set by the system.
- Use
- Export Formatting:
- Use
export_format
to specify how dates appear in exports. - Use
export_timezone
to ensure consistent timezone handling in exports.
- Use
- Use Cases:
- Personal Information: Date of birth, anniversary dates.
- Scheduling: Appointment times, meeting dates, deadlines.
- Tracking: Creation dates, modification dates, completion dates.
- Business Processes: Start dates, end dates, due dates.
- Historical Data: Event dates, milestone dates.
- Internationalization:
- Be mindful of date format preferences in different locales.
- Consider timezone differences when dealing with global applications.
- Ensure that date validation rules are appropriate for the target audience.
- Accessibility:
- Provide clear labels and guidance for date input.
- Ensure that date pickers are keyboard accessible.
- Consider providing multiple input methods (text input, calendar picker).
By incorporating the date
field type into your schema, you ensure consistent and reliable capture of temporal data, which is essential for scheduling, tracking, and temporal analysis within your application.