简体   繁体   中英

What causes datepicker not loading in rails 3.1.3 with jquery?

We have a very simple use of datepicker in rails 3.1.3 app with jquery. However there are 2 views on which datepicker does not load. On all other views, datepicker loads itself without problem. All js code for datepicker is in application.js file and one of them (not loading) looks like this (with head file):

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

$(function() {
   $("#src_plant_src_since").datepicker({dateFormat: 'yy-mm-dd'});
});

Here is the simple form code in view:

<%= f.input :src_since, :label => 'start date:', :hint => 'start src date', :as => :string %>

What could be the reason causing datepicker loads on one view and not one another? Thanks so much.

Gemfile

group :assets do
    gem 'jquery-ui-rails'
end

application.js

//= require jquery
//= require jquery_ujs
//= require jquery.ui.all 
//= require_tree .

Or you can load only the datepicker js. Like:

//= require jquery.ui.datepicker

Try this

install

gem "jquery_datepicker"

then this in ur form

<%= f.label :date %>
 <%= f.datepicker :date, :dateFormat => 'dd MM, yy',  :showOn => "both", :buttonImage => "../assets/calendar.gif", :buttonImageOnly => true, :changeMonth => true, :changeYear => true, :placeholder => "Click on the textfield/Calender" %><br/>

This u should put inside application.html inside your layouts

<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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