Date Format
Set how the date and date-time pickers across Catalyst show their values. Formats are Ruby strftime strings β the same notation used for the format: option on columns and fields β and default to Dec 13, 2026 / Dec 13, 2026, 2:29 PM style output.
Quick exampleβ
Catalyst.configure do |config|
config.display_date_format = "%d/%m/%Y" # 06/08/2026
config.display_datetime_format = "%b %-d, %Y %I:%M %p" # Aug 6, 2026 02:30 PM
end
Optionsβ
| Option | Default | Description |
|---|---|---|
display_date_format | "%b %-d, %Y" | Format of date pickers. |
display_datetime_format | "%b %-d, %Y, %-I:%M %p" | Format of date-time pickers (12-hour). |
Date-time pickers always offer a 12-hour time control with an AM/PM toggle; use %I/%p (or %H for 24-hour) to match the displayed text. Date range filters show both dates in display_date_format, joined by to.
Supported directivesβ
| Directive | Output |
|---|---|
%Y / %y | 2026 / 26 |
%B / %b (%h) | August / Aug |
%A / %a | Thursday / Thu |
%m / %-m | 08 / 8 |
%d / %-d / %e | 06 / 6 / 6 |
%H / %k | 14 / 14 (24-hour, %k space-pads) |
%I / %l | 02 / 2 (12-hour) |
%M | 05 (minutes) |
%S | 00 (seconds) |
%p / %P | PM / pm |
%% | % |
%F, %D, %R, %T, %r, %v | Compound formats (%Y-%m-%d, %m/%d/%y, %H:%M, %H:%M:%S, %I:%M:%S %p, %e-%b-%Y) |
The - and _ flags work on the numeric directives (%-d β 6, %_d β 6). Typed values are read back with the same format; ISO values (2026-08-06) are always accepted too.
The formats are exposed to JavaScript as window.catalystConfig.displayDateFormat and window.catalystConfig.displayDateTimeFormat. They only change what the picker shows: forms still submit ISO values (see below).
Submitted valuesβ
Forms submit ISO values: YYYY-MM-DD for dates, YYYY-MM-DDTHH:MM for date-times (a UTC timestamp, YYYY-MM-DDTHH:MM:00Z, for fields with a timezone: option) and YYYY-MM-DD to YYYY-MM-DD for date range filters.
Setting the value from JavaScriptβ
Each picker renders two inputs: a visible text field (data-datepicker-target="input") that shows the formatted date and accepts typing, and a hidden input (data-datepicker-target="value") that carries the field's name and the submitted ISO value. The datepicker Stimulus controller keeps them in sync automatically β assigning .value on either input updates the other, the calendar's selection, and the clear button. No extra calls are needed:
const wrapper = document.querySelector('[data-controller~="datepicker"]');
// via the hidden input β visible text and calendar selection update
wrapper.querySelector('[data-datepicker-target="value"]').value = "2026-11-23";
// or via the visible input β parsed like typed text (display format or ISO)
wrapper.querySelector('[data-datepicker-target="input"]').value =
"Nov 23, 2026";
The two writes differ in notification, mirroring user behaviour:
-
Hidden input β syncs silently, like the controller's own
refresh(). Dispatchchangeon it yourself if listeners (like date filters) should react:const hidden = wrapper.querySelector('[data-datepicker-target="value"]');hidden.value = "2026-11-23";hidden.dispatchEvent(new Event("change", { bubbles: true })); -
Visible input β commits like typed input: the text is parsed (unparseable text reverts to the last valid value), the hidden input syncs, and
changefires on it.
To clear a picker from JavaScript, assign "" β or call controller.clear() where controller is window.Stimulus.getControllerForElementAndIdentifier(wrapper, "datepicker") (this.application.β¦ inside another Stimulus controller).
Reacting to user changesβ
The other direction works through the hidden input too: when the user picks a date from the calendar or finishes typing, the controller writes the committed ISO value into it and dispatches change. Listen for change on the hidden input β it bubbles, so a delegated listener on a parent form works as well:
wrapper.addEventListener("change", (event) => {
if (event.target.matches('[data-datepicker-target="value"]'))
console.log(event.target.value); // "2026-11-23"
});
The event fires once per committed value β on each pick for date and date-time fields, and when the calendar closes for date range filters β and does not re-fire when the same value is picked again. This is the mechanism Catalyst's own date filters use: their hidden input carries the change listener that submits the filter.
Recipesβ
Navigate a wider year rangeβ
Date pickers limit year navigation to Β±50 years around the current year. To let users pick from a wider range (1900β2199), set data-default-year-selector on the input, and add data-min-date / data-max-date (ISO YYYY-MM-DD) if the field needs a custom range:
form_field :birth_date, input_type: :date,
html_attrs: { data: { default_year_selector: true, max_date: Date.current.iso8601 } }