How to add time picker in Active Admin + Rails 3

Amal Kumar S picture Amal Kumar S · Nov 2, 2012 · Viewed 14.6k times · Source

I need to display time selector in my active admin form. I have a field start_time which is of type time. Currently I have drop-downs.

enter image description here

I need a selector similar to date picker as shown

enter image description here

For adding Date Picker I used

f.input :start_date, :as => :datepicker

ActiveAdmin.register PromoCode do

  form :html => { :enctype => "multipart/form-data" } do |f|  
    f.inputs "PromoCodes" do
    f.input :promo_code
    f.input :start_date, :as => :datepicker
    f.input :start_time
  end
  f.buttons
 end

end

Is there similar way to get time picker in active admin. Please help.

Answer

HungryCoder picture HungryCoder · Nov 2, 2012

Though the datepicker will show a calendar to chose a date form, i've no idea how a time picker would work! Should it show a clock :)?

However, there is another selector in formtastic (which is used by activeadmin). that is time_picker. So you use that as follow:

f.input :start_time, :as => :time_picker

More is in the Doc