railsadminteam/rails_admin · warning

The momentjs_format configuration option is deprecated, plea

Error message

The momentjs_format configuration option is deprecated, please use flatpickr_format with corresponding values here: https://flatpickr.js.org/formatting/

What it means

RailsAdmin swapped its date/time picker from moment.js to flatpickr. The datetime field type kept momentjs_format (lib/rails_admin/config/fields/types/datetime.rb:85) only as a deprecated stub whose block prints this ActiveSupport::Deprecation warning; the format string you pass is discarded. Date formatting/parsing now goes through the flatpickr_format instance option, using flatpickr's token syntax.

Source

Thrown at lib/rails_admin/config/fields/types/datetime.rb:86

          register_instance_option :queryable? do
            false
          end

          register_instance_option :formatted_value do
            time = (value || default_value)
            if time
              ::I18n.l(time, format: strftime_format)
            else
              ''.html_safe
            end
          end

          register_instance_option :partial do
            :form_datetime
          end

          register_deprecated_instance_option :momentjs_format do
            ActiveSupport::Deprecation.warn('The momentjs_format configuration option is deprecated, please use flatpickr_format with corresponding values here: https://flatpickr.js.org/formatting/')
          end

          def form_value
            value&.in_time_zone&.strftime('%FT%T') || form_default_value
          end
        end
      end
    end
  end
end

View on GitHub (pinned to 0690a5e62f)

Solutions

  1. Replace momentjs_format with flatpickr_format and translate the tokens — moment 'YYYY-MM-DD HH:mm' becomes flatpickr 'Y-m-d H:i' (reference: https://flatpickr.js.org/formatting/).
  2. After switching, exercise the create/edit form of that model once and confirm the picker parses and redisplays values in the expected format, since wrong tokens fail silently rather than raising.
  3. Grep for momentjs_format across initializers (and any per-model config blocks) — each occurrence warns separately.

Example fix

# before
RailsAdmin.config do |config|
  config.model Post do
    field :published_at, :datetime do
      momentjs_format 'YYYY-MM-DD HH:mm'
    end
  end
end

# after (flatpickr tokens: https://flatpickr.js.org/formatting/)
RailsAdmin.config do |config|
  config.model Post do
    field :published_at, :datetime do
      flatpickr_format 'Y-m-d H:i'
    end
  end
end
Defensive patterns

Strategy: validation

Validate before calling

# Translate and validate up front instead of porting blindly
MOMENT_TO_FLATPICKR = { 'YYYY' => 'Y', 'YY' => 'y', 'MM' => 'm', 'DD' => 'd', 'HH' => 'H', 'hh' => 'h', 'mm' => 'i', 'ss' => 'S', 'A' => 'K' }.freeze
moment = 'YYYY-MM-DD HH:mm'
flatpickr = moment.gsub(Regexp.union(MOMENT_TO_FLATPICKR.keys), MOMENT_TO_FLATPICKR) # => 'Y-m-d H:i'
raise 'untranslated tokens remain' unless flatpickr.scan(/[A-Za-z]/ - %w[Y m d H i]).empty?

Prevention

When it happens

Trigger: A field config like `field :published_at, :datetime do momentjs_format 'YYYY-MM-DD HH:mm' end`. The warning fires when that model config is evaluated (first admin request touching the model), and — worse — the picker silently falls back to the default flatpickr format, so the form renders the wrong format with no error.

Common situations: Upgrading an app from rails_admin that used moment.js (< the flatpickr switch) and keeping the old initializer verbatim; moment format tokens ('YYYY', 'HH:mm') silently meaning nothing to flatpickr ('Y', 'H:i'); CI with deprecations promoted to errors failing on admin specs.

Related errors


AI-assisted analysis of railsadminteam/rails_admin@0690a5e62f (2026-08-21). Data as JSON: /api/errors/f431cbe7cdcc0422. Report an issue: GitHub.