Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Admin date filter date format customisation

Is there simple way to change the ActiveAdmin date filter display format from the default ISO format (yyyy-mm-dd)?

like image 728
Toby Hede Avatar asked Sep 13 '12 11:09

Toby Hede


2 Answers

Instead of overwriting the js you can provide extra options to the datepicker like this:

 = f.input :my_date, as: :datepicker, datepicker_options: { dateFormat: "mm/dd/yy" }
like image 154
Nathan Bertram Avatar answered Oct 18 '22 22:10

Nathan Bertram


The way i fixed is is like this:

$ ->
  # reset format
  $('.datepicker:not(.hasDatepicker)').each ->
    if $(@).val().length > 0
      p = $(@).val().split('-')
      $(@).val("#{p[2]}-#{p[1]}-#{p[0]}")

  # change format
  $(document).on 'focus', '.datepicker:not(.hasDatepicker)', ->
    $(@).datepicker dateFormat: 'dd-mm-yy'

So first reset the value from yyyy-mm-dd to yyyy-mm-dd, than set the correct format on the picker.

Hope this helps someone.

This works in ActiveAdmin pre 1 with the just_datetime_picker gem

like image 27
Rene Weteling Avatar answered Oct 18 '22 23:10

Rene Weteling