Skip to main content

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​

OptionDefaultDescription
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 } }