简体   繁体   中英

Value for date input not displayed when using localization, formtastic and activeadmin

I have a model with a column date of type date.

I'm using ui_datepicker-rails3 with activeadmin and in my form I have:

form do |f|
    f.inputs do
        f.input :date, :as => :ui_date_picker
    end
end

The format of the date is dd/mm/yy .

The problem is that after I send the form, if it has errors and the controller renders the new view, then the value of the input is ok but I can't see the date inside the input field. For example:

I fill date with 20/08/2012 and I send the form. When it renders back the input is

<input class="datepicker ui-date-picker hasDatepicker" id="progress_date" name="progress[date]" type="text" value="28/08/2012">

But the input doesn't show the value on screen.

When I send it formatted as yy-mm-dd it works fine.

What could it be?

ActiveAdmin define a custom DatepickerInput which add the datepicker class to date fields.

Objects with this class are formatted to 'yy-mm-dd' by AA.

To avoid this, put this code in an initializer:

module ActiveAdmin
  module Inputs
    class DatepickerInput < ::Formtastic::Inputs::StringInput
      def input_html_options
        super
      end
    end
  end
end

It removes the datepicker class to date inputs and left them with ui-date-picker hasDatepicker .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM