Starting a new Rails 4 : III. a date picker bootstrap 3, rails 4, datepicker
Seeking a BS3 date picker …
There a library for bootstrap 2 (https://github.com/eternicode/bootstrap-datepicker) but she’s not ready for bootstrap 3 … So I found a fork here : https://github.com/ianserlin/bootstrap-datepicker/tree/3.x and use it until the standard library will update.
Install
Just copy the CSS file and the JS file to you assets rails directory.
Usage
Two step : declare the class for the date picker, and place the javascript call. In view/users/_form.html.haml :
= simple_form_for @user, :html => {:class => 'well form-horizontal'} do |f|
= f.error_notification
= f.input :username
= f.input :lastname
= f.input :identity
= f.input :email
= f.input :birthdate, :as => :string, :input_html => {:class => 'datepicker col-span-3'}
= f.input :active
.form-actions
= f.submit "Update", :class => "btn btn-primary"
= submit_tag 'Cancel', :type => :reset, :class => "btn btn-danger"
:javascript
$('.datepicker').datepicker({
format: "yyyy-mm-dd",
todayHighlight: true,
todayBtn: 'linked',
autoclose: true
}); ;
Note that the date format must match the database date format. Check the documentation for the options.
Tweetcomments powered by Disqus