如何在 rails 上以 bootstrap 形式使用日期选择器
how to use date picker in bootstrap form on rails
我使用 rails-bootstrap-forms
gem 在 rail 应用程序中创建一个表单。在表格中,我输入了一个日期:
<%= f.date_select :end_date, hide_label: true %>
我想在 bootstrap-datepicker-rails
gem 中使用日期选择器,它举了一个例子:
<input type="text" class='datepicker' >
<script type="text/javascript">
$(document).ready(function(){
$('.datepicker').datepicker();
});
</script>
或
<input type="text" data-provide='datepicker' >
我按照这个 answer 并更改了我的代码,但它没有用:
<%= f.text_field :start_date, hide_label: true, class: 'datepicker' %>
<script type="text/javascript">
$(document).ready(function(){
$('.datepicker').datepicker();
});
</script>
然后,我按照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.
并将我的代码更改为:
<%= 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
这应该有效:
<%= f.text_field :start_date, hide_label: true, class: 'datepicker' %>
我使用 rails-bootstrap-forms
gem 在 rail 应用程序中创建一个表单。在表格中,我输入了一个日期:
<%= f.date_select :end_date, hide_label: true %>
我想在 bootstrap-datepicker-rails
gem 中使用日期选择器,它举了一个例子:
<input type="text" class='datepicker' >
<script type="text/javascript">
$(document).ready(function(){
$('.datepicker').datepicker();
});
</script>
或
<input type="text" data-provide='datepicker' >
我按照这个 answer 并更改了我的代码,但它没有用:
<%= f.text_field :start_date, hide_label: true, class: 'datepicker' %>
<script type="text/javascript">
$(document).ready(function(){
$('.datepicker').datepicker();
});
</script>
然后,我按照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.
并将我的代码更改为:
<%= 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
这应该有效:
<%= f.text_field :start_date, hide_label: true, class: 'datepicker' %>