CxJS

DateTimeField

import { DateTimeField } from 'cx/widgets'; Copied

The DateTimeField widget is used for selecting date, time, or datetime values. It supports textual input and picking from a dropdown.

Use TimeField as a shorthand alias for DateTimeField with segment="time". The picker="list" option displays time options in a scrollable list with configurable step intervals.

<LabelsTopLayout columns={2}>
  <DateTimeField
    label="Date & Time"
    value={bind(m.datetime, "2024-06-15T14:30:00")}
    autoFocus
  />
  <DateTimeField
    label="Time (segment)"
    value={bind(m.time, "2024-06-15T14:30:00")}
    segment="time"
  />
  <TimeField label="TimeField alias" value={m.time} />
  <TimeField label="List picker" value={m.time} picker="list" step={15} />
  <DateTimeField
    label="Placeholder"
    value={m.placeholder}
    placeholder="Select date & time..."
  />
  <DateTimeField label="Disabled" value={m.datetime} disabled />
</LabelsTopLayout>

Partial Mode

Combine DateField and TimeField to edit the same datetime value. Use the partial flag to indicate that each field affects only its respective segment of the date.

<LabelsTopLayout columns={2}>
  <DateField
    label="Date"
    value={bind(m.datetime, "2024-06-15T14:30:00")}
    partial
  />
  <TimeField label="Time" value={m.datetime} partial />
</LabelsTopLayout>

Configuration

Core Properties

PropertyTypeDefaultDescription
valuestringnullSelected date/time value. Accepts Date objects or ISO strings
segmentstring"datetime"Mode of operation: "datetime", "date", or "time"
formatstringCustom format for displaying the value
placeholderstringPlaceholder text when no value is selected
disabledbooleanfalseDisables the field
readOnlybooleanfalseMakes the field read-only
iconstring"calendar"Icon displayed on the left side of the input

Date Constraints

PropertyTypeDefaultDescription
minValuestringMinimum selectable date/time
minExclusivebooleanfalseIf true, the minimum value itself is not selectable
maxValuestringMaximum selectable date/time
maxExclusivebooleanfalseIf true, the maximum value itself is not selectable
disabledDaysOfWeeknumber[]Days of week that cannot be selected. Sunday is 0, Saturday is 6

Picker Options

PropertyTypeDefaultDescription
pickerstring"auto"Picker type: "auto", "calendar", or "list"
stepnumberTime step in minutes when using picker="list"
showSecondsbooleanfalseShow seconds in the time picker
partialbooleanfalseOnly update the relevant segment (date or time) of existing value
focusInputFirstbooleanfalseFocus the input field instead of the picker when opening
dropdownOptionsobjectAdditional configuration for the dropdown
encodingfunctionCustom function to encode Date objects before storing

Appearance

PropertyTypeDefaultDescription
showClearbooleantrueShows a clear button when value is present
hideClearbooleanfalseHides the clear button (opposite of showClear)
alwaysShowClearbooleanfalseShows clear button even when field is required
inputStyleobjectCSS styles for the input element
inputClassstringCSS class for the input element
inputAttrsobjectAdditional attributes for the input element

Validation

PropertyTypeDefaultDescription
minValueErrorTextstring"Select {0:d} or later."Error message when value is before minimum
minExclusiveErrorTextstring"Select a date after {0:d}."Error message when value equals exclusive minimum
maxValueErrorTextstring"Select {0:d} or before."Error message when value is after maximum
maxExclusiveErrorTextstring"Select a date before {0:d}."Error message when value equals exclusive maximum
inputErrorTextstring"Invalid date entered."Error message for invalid input
disabledDaysOfWeekErrorTextstring"Selected day of week is not allowed."Error for disabled day of week

Behavior

PropertyTypeDefaultDescription
autoFocusbooleanfalseAutomatically focuses the field on mount
reactOnstring"enter blur"Events that trigger value update: "enter", "blur"