kristianmandrup / ui_datepicker-rails3

jQuery UI datepicker integration for Formtastic, Simple Form and Active Admin
MIT License
50 stars 15 forks source link

UiDatePickerInput for ActiveAdmin doesn't localized values #13

Open bishma-stornelli opened 12 years ago

bishma-stornelli commented 12 years ago

I'm using AA and when I edit an entity which has a date attribute, it's not localized.

I had to add this:

module ActiveAdmin
  module Inputs
    class UiDatePickerInput < ::ActiveAdmin::Inputs::DatepickerInput
      def input_html_options
        options = super
        options[:class] = [options[:class], "ui-date-picker"].compact.join(' ')
        options[:value] = localized(value) 
        options
      end

      def localized value
        value.nil? ? nil : I18n.localize(object.send(method))
      end  

      def value
        input_options[:value] || object.send(method).try(:strftime, format)
      end

      def format
        input_options[:format] || '%d %b %Y'
      end
    end
  end
end

in an initializer to make it work