jQuery UI datepicker无法与Rails一起使用 [英] jQuery UI datepicker not working with Rails
问题描述
我试图基于以下内容为我的Rails应用程序安装jQuery UI Datepicker: https://github.com/joliss/jquery-ui-rails ,以及有关该主题的修订版Railscast和无数尝试使此工作正常进行的线程.不管我尝试什么,它似乎都行不通.
I am trying to install the jQuery UI Datepicker for my Rails application based on: https://github.com/joliss/jquery-ui-rails, as well as the Revised Railscast on this topic and countless threads trying to get this working. No matter what I try it does not seem to work.
application.js
//= require jquery
//= require jquery_ujs
//= require jquery.ui.datepicker
//= require_tree .
//= require tinymce-jquery
application.css
*= require jquery.ui.datepicker
*= require_self
*= require_tree .
new.html.erb
<%= f.label :due_date %>
<%= f.text_field :due_date %>
modelname.js.coffee
jQuery ->
$('#modelname_due_date').datepicker (dateFormat: 'dd-mm-yy')
这似乎是我完成这项工作所需的全部,但是我尝试了许多变种但无济于事.在Chrome中进行调试时,不会向控制台抛出任何错误.感谢您的帮助.
This seems to be all I need to make this work, however I have tried many variations to no avail. There are no errors thrown to the console when debugging in Chrome. Any help is appreciated.
推荐答案
尝试为您的输入字段提供一个类,如下所示:
Try to give a class to your input field , like this:
<%= f.text_field :due_date,class: "modelname_due_date %>
如果使用类选择器,则应更改javascript代码:
In case of using class selector, javascript code should be changed:
$('.modelname_due_date').datepicker (dateFormat: 'dd-mm-yy')
然后,您将触发javascript代码.
Then you will have javascript code triggered.
这篇关于jQuery UI datepicker无法与Rails一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!