Skip to main content

CmAdmin Date & Date-Time Display Format Configuration

Configure how dates and date-times are displayed across the cm-admin interface.


1. Configuration​

In zcm_admin.rb (initializer):

CmAdmin.configure do |config|
config.display_date_format = 'd-m-Y' # Default: 'd-m-Y'
config.display_datetime_format = 'd-m-Y H:i' # Default: 'd-m-Y H:i'
end

Use any format supported by flatpickr.


2. How It Works​

  • Formats are exposed as JavaScript variables:

    window.cmAdminConfig.displayDateFormat
    window.cmAdminConfig.displayDateTimeFormat
  • Used by flatpickr to render pickers consistently.


3. Example​

To use format Y/m/d for date and Y/m/d H:i for date-time:

CmAdmin.configure do |config|
config.display_date_format = 'Y/m/d'
config.display_datetime_format = 'Y/m/d H:i'
end

4. Notes​

  • If not set, defaults will apply. (See above)

5. Year Select Dropdown​

By default, date pickers include a year-select dropdown in the month navigation, making it easy to jump to years far in the past or future.

To use flatpickr's default year navigation for a specific field instead, set the data-default-year-selector attribute on the input:

form_field :birth_date, input_type: :date, html_attrs: { data: { default_year_selector: true } }

The default year navigation lets users type any year in the month header. Unlike the year-select dropdown, it is not limited to a ±50-year window, so set data-min-date / data-max-date (ISO YYYY-MM-DD) if the field needs an explicit range.


6. References​