简体   繁体   English

jQuery-ui datepicker与ransack

[英]Jquery-ui datepicker with ransack

I am trying to set a date range filter with ransack. 我正在尝试使用ransack设置日期范围过滤器。 So in my view: 所以我认为:

 <%= f.text_field :DATE_gteq, :id => "datepicker" %>
 <%= f.text_field :DATE_lteq, :id => "datepicker" %>

And I'm using jquery-ui datepicker. 我正在使用jquery-ui datepicker。

To set it up: 进行设置:

Gemfile: 宝石文件:

gem 'jquery-ui-rails' 

application.js application.js

//= require turbolinks
//= require jquery
//= require jquery_ujs
//= require jquery-ui/datepicker

$("#datepicker").datepicker();

application.scss application.scss

@import 'jquery-ui/datepicker';

application.html.erb application.html.erb

 <script>
      $(function() {
          $( "#datepicker" ).datepicker();
      });
  </script>
  </body>

The problem is that in view when I click on the first search field it does show the calendar, when I click on the second one nothing happens. 问题是,在视图中,当我单击第一个搜索字段时,它确实显示了日历,而当我单击第二个搜索字段时,没有任何反应。

What could be the cause? 可能是什么原因?

Note: You can't have multiple duplicate id's on same page 注意:同一页上不能有多个重复的ID

Use a class in the view and call as below: 在视图中使用类并按如下所示调用:

$('.datepicker').each(function(){
    $(this).datepicker();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM