Catmal Catmal - 1 year ago 158
Javascript Question

Jquery-ui datepicker with ransack

I am trying to set a date range filter with 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.

To set it up:


gem 'jquery-ui-rails'


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



@import 'jquery-ui/datepicker';


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

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?

Answer Source

Note: You can't have multiple duplicate id's on same page

Use a class in the view and call as below:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download