CxJS

DateField

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

The DateField widget is used for selecting dates. It supports both text input and picking from a dropdown calendar.

<LabelsTopLayout columns={2}>
  <DateField label="Standard" value={bind(m.date, "2024-06-15")} autoFocus />
  <DateField label="Disabled" value={m.date} disabled />
  <DateField label="Read-only" value={m.date} readOnly />
  <DateField
    label="Placeholder"
    value={m.placeholder}
    placeholder="Select a date..."
  />
  <DateField label="Required" value={m.date} required />
  <DateField
    label="Weekends Disabled"
    value={m.date}
    disabledDaysOfWeek={[0, 6]}
  />
</LabelsTopLayout>

Configuration

Core Properties

PropertyTypeDefaultDescription
valuestringnullSelected date. Accepts Date objects or ISO strings
formatstring"date;yyyyMMMdd"Display format. See Formatting
placeholderstringHint text displayed when the field is empty
disabledbooleanfalseDisables the input
enabledbooleanOpposite of disabled
readOnlybooleanfalseMakes the input read-only
requiredbooleanfalseMarks the field as required
labelstringField label text
viewModebooleanfalseDisplay as plain text instead of interactive input
emptyTextstringText shown in view mode when the field is empty

Date Constraints

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

Validation

PropertyTypeDefaultDescription
minValueErrorTextstring"Select {0:d} or later."Error message when date is before minimum
minExclusiveErrorTextstring"Select a date after {0:d}."Error message when date equals exclusive minimum
maxValueErrorTextstring"Select {0:d} or before."Error message when date is after maximum
maxExclusiveErrorTextstring"Select a date before {0:d}."Error message when date equals exclusive maximum
inputErrorTextstring"Invalid date entered."Error message for invalid date input
errorstringCustom error message. Field is marked invalid if set
visitedbooleanIf true, shows validation errors immediately
validationModestring"tooltip"How to show errors: "tooltip", "help", "help-block"

Appearance

PropertyTypeDefaultDescription
iconstring/object"calendar"Icon on the left side
showClearbooleantrueShows a clear button when the field has a value
hideClearbooleanfalseOpposite of showClear
alwaysShowClearbooleanfalseShows clear button even when field is required
tooltipstring/objectTooltip text or configuration
inputStylestring/objectCSS styles applied to the input element
inputClassstringCSS class applied to the input element

Behavior

PropertyTypeDefaultDescription
autoFocusbooleanfalseAutomatically focuses the field on mount
focusInputFirstbooleanfalseFocus the text input instead of the calendar when opened
partialbooleanfalsePreserves time segment when combined with a time field
encodingfunctionCustom function to encode Date objects before storing. Default: toISOString()
onParseInputfunctionCustom parser for text input, e.g., to handle “today”
dropdownOptionsobjectAdditional configuration for the dropdown

Callbacks

PropertyTypeDescription
onValidatefunction`(value, instance, validationParams) => string