4

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')

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.

3
  • Check the console(Chrome Dev tools), any errors? Commented Apr 22, 2013 at 18:30
  • No errors are being thrown to the console, it simply does nothing when I click into the text field. Commented Apr 22, 2013 at 18:37
  • after page load, can you try the javascript statement to create datepicker in chrome chosole ? i.e. $('#modelname_due_date').datepicker (dateFormat: 'dd-mm-yy') Then try to focus of text field. If that works then something is wrong in loading component, if that's not then something is missing / wrong to create datepicker Commented Apr 22, 2013 at 19:35

1 Answer 1

6

Try to give a class to your input field , like this:

<%= f.text_field :due_date,class: "modelname_due_date %>

In case of using class selector, javascript code should be changed:

$('.modelname_due_date').datepicker (dateFormat: 'dd-mm-yy')

Then you will have javascript code triggered.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the reply. The class name is now added to my field, unfortunately the datepicker is still not working :(
Check your Gemfile for gem 'jquery-ui-rails'. What is exactly your Model name?
Gem is there. Model name is simply 'project'. So class name and id is 'project_due_date'.
Somehow it now works. I completely shut down my server, re-ran bundle update and 'bundle exec rake assets:precompile'. Anyway thanks for all of the helpful replies.
@RumenMilushev , any idea how to fix this: stackoverflow.com/questions/20336585/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.