Date Format
Set the format the flatpickr date and date-time pickers use across cm-admin.
Quick exampleβ
config/initializers/cm_admin.rb
CmAdmin.configure do |config|
config.display_date_format = "Y/m/d"
config.display_datetime_format = "Y/m/d H:i"
end
Optionsβ
| Option | Default | Description |
|---|---|---|
display_date_format | "d-m-Y" | Format of date pickers. Any flatpickr format. |
display_datetime_format | "d-m-Y H:i" | Format of date-time pickers. |
They are exposed to JavaScript as window.cmAdminConfig.displayDateFormat and window.cmAdminConfig.displayDateTimeFormat.
To format values on index and show pages, use the format option of column or field (a Ruby strftime string such as "%d %b, %Y").
Recipesβ
Use flatpickr's own year navigationβ
Date pickers show a year dropdown limited to Β±50 years. To let users type any year instead, 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 range:
form_field :birth_date, input_type: :date,
html_attrs: { data: { default_year_selector: true, max_date: Date.current.iso8601 } }