how to use date picker in bootstrap form on rails
我使用
我想在
1 2 3 4 5 6 | <input type="text" class='datepicker' > <script type="text/javascript"> $(document).ready(function(){ $('.datepicker').datepicker(); }); |
要么
1 | <input type="text" data-provide='datepicker' > |
我按照这个答案改变了我的代码,但它没有用:
1 2 3 4 5 | <%= f.text_field :start_date, hide_label: true, class: 'datepicker' %> <script type="text/javascript"> $(document).ready(function(){ $('.datepicker').datepicker(); }); |
然后,我按照bootstrap_form中的描述:
If you want to add an additional css class or any other attribute to the form group div, you can use the wrapper: { class: 'additional-class', data: { foo: 'bar' } } option.
并将我的代码更改为:
1 | <%= f.text_field :start_date, hide_label: true, wrapper: {class: 'datepicker'} %> |
它没有用。 那么如何解决这个问题呢? 谢谢。
检查应用程序js和css以查找所需文件
Configuration
Add this line to app/assets/stylesheets/application.css
*= require bootstrap-datepicker
Or if using bootstrap v3:
*= require bootstrap-datepicker3
Add this line to app/assets/javascripts/application.js
//= require bootstrap-datepicker
这应该工作:
1 | <%= f.text_field :start_date, hide_label: true, class: 'datepicker' %> |