Add datepicker with rails 3.2.11, simple_form and bootstrap

喜欢而已 提交于 2019-12-07 18:52:24

问题


I am trying to implement datepicker in my simple_form much as has been covered here: How do i write a cleaner date picker input for SimpleForm

I create the custom class:

# app/inputs/date_picker_input.rb
class DatePickerInput < SimpleForm::Inputs::StringInput
....
end

I then add: `$("input.date_picker").datepicker();

at the bottom of application.js and use the code:

<%= f.input :deadline, :as => :date_picker %>

However, a datepicker is not activated, nor is an error thrown. Could this be an issue with me not understanding the asset pipeline correctly? My application.js also contains: //= require jquery.ui.datepicker.min

I also use the datepicker on a separate page in my application that does not use simple_form, so datepicker by itself is working.

Any suggestions would be appreciated.


回答1:


Make sure datepicker is called in your JavaScript (change datepicker class if it is different in your form):

$(function() {
  $('input.datepicker').datepicker();
});

Also you can check How do i write a cleaner date picker input for SimpleForm or https://github.com/plataformatec/simple_form/issues/75#issuecomment-448362



来源:https://stackoverflow.com/questions/14452942/add-datepicker-with-rails-3-2-11-simple-form-and-bootstrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!