Forked from mvilrokx/jquery-ui-datepicker-rails-part3.html.haml
Created
September 9, 2020 21:13
-
-
Save movstox/6ba533f03474c29d4b2d05d813c75463 to your computer and use it in GitHub Desktop.
Adding jquery-ui datepicker to rails view with Alternate Field and format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment