CxJS

MonthField

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

The MonthField widget is used for selecting months or month ranges. It displays a dropdown with a month picker for easy selection.

<LabelsTopLayout columns={2}>
  <MonthField
    label="Single Month"
    value={bind(m.month, "2024-06-01")}
    autoFocus
  />
  <MonthField
    label="Month Range"
    range
    from={bind(m.from, "2024-03-01")}
    to={bind(m.to, "2024-06-01")}
  />
  <MonthField
    label="Placeholder"
    value={m.placeholder}
    placeholder="Select a month..."
  />
  <MonthField label="Disabled" value={m.month} disabled />
</LabelsTopLayout>

Range Selection

In range mode, the month picker provides quick selection options:

  • Click on a year (e.g., “2024”) to select the entire year (Jan - Dec)
  • Click on a quarter (Q1, Q2, Q3, Q4) to select all three months in that quarter
  • Drag across months to select a custom range, similar to selecting text

Configuration

Core Properties

PropertyTypeDefaultDescription
valuestringnullSelected month (for single mode). Accepts Date or ISO string
rangebooleanfalseEnable range selection mode
fromstringStart of selected range (when range is true)
tostringEnd of selected range (when range is true)
inclusiveTobooleanfalseWhether the to date is included in the range
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 month
minExclusivebooleanfalseIf true, the minimum month itself is not selectable
maxValuestringMaximum selectable month
maxExclusivebooleanfalseIf true, the maximum month itself is not selectable

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

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

Behavior

PropertyTypeDefaultDescription
autoFocusbooleanfalseAutomatically focuses the field on mount
reactOnstring"enter blur"Events that trigger value update
encodingfunctionCustom function to encode Date objects before storing
dropdownOptionsobjectAdditional configuration for the dropdown
monthPickerOptionsobjectConfiguration options for the MonthPicker in dropdown