Adding jquery-ui datepicker to rails view with Alternate Field and format

  • Download Gist
jquery-ui-datepicker-rails-part3.html.haml
Haml
1 2 3 4 5 6 7 8 9 10 11 12
# in your view (HAML + simple_form, simplified for easier reading)
= simple_form_for @bp_reading do |f|
= f.input :recorded_at, :as => :string, :input_html => { :class => 'jquery-ui-date', :value => @bp_reading.try(:recorded_at).try(:strftime,'%m/%d/%Y')}
= f.input :recorded_at, :as => :hidden, :input_html => { :id => 'recorded-at-alt'}
= f.button :submit, :disable_with => "Saving...", :value => "Save"
 
# in your javascript (coffeescript)
$ ->
$(".jquery-ui-date").datepicker(
altField: "#recorded-at-alt",
altFormat: "yy-mm-d"
)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.