添加带有 rails 3.2.11、simple_form 和 bootstrap 的日期选择器 [英] Add datepicker with rails 3.2.11, simple_form and bootstrap

查看:46
本文介绍了添加带有 rails 3.2.11、simple_form 和 bootstrap 的日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 simple_form 中实现 datepicker,就像这里介绍的那样:如何为 SimpleForm 编写更清晰的日期选择器输入

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

我创建自定义类:

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

然后我添加:`$("input.date_picker").datepicker();

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

在 application.js 底部并使用代码:

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

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

然而,日期选择器没有被激活,也没有抛出错误.这可能是我没有正确理解资产管道的问题吗?我的 application.js 还包含://= 需要 jquery.ui.datepicker.min

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

我还在我的应用程序的一个单独页面上使用了 datepicker,该页面不使用 simple_form,所以 datepicker 本身就可以工作.

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.

推荐答案

确保在 JavaScript 中调用 datepicker(如果表单中的 datepicker 类不同,请更改它):

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

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

你也可以检查我如何编写更清晰的日期选择器输入简单表格https://github.com/plataformatec/simple_form/issues/75#issuecomment-448362

这篇关于添加带有 rails 3.2.11、simple_form 和 bootstrap 的日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆