0

I am trying to use the http://trentrichardson.com/examples/timepicker/ plugin.

In my gemfile, I have (and I made sure the gem is installed):

gem 'jquery-rails'

I downloaded jquery-ui-timepicker-addon.js into the app/assets/javascripts directory

I added the CSS section to app/assets/stylesheets/application.css.erb

I added the following to app/assets/javascript/application.js:

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jquery-ui-timepicker-addon

$(
  function() {
    $('.date_with_hours_and_minutes').datetimepicker(
      {dateFormat: 'yy-mm-dd hh:mm'}   )
  }
);

In my view, I have:

<%= f.text_field :start_date_time, id: "date_with_hours_and_minutes" %>

I am not getting any errors, but I am not seeing the datetime picker either. Any ideas?

2
  • 1
    are the two periods in $('.date_with_hours_and_minutes')..datetimepicker a typo in your question or in your code? Commented Aug 24, 2012 at 16:36
  • Typo in in the question. I was fixing it while you were writing your comment :-) Commented Aug 24, 2012 at 16:45

2 Answers 2

2

try

$('#date_with_hours_and_minutes').datetimepicker(

you need to attack the id

Update

In addition to the above, I notice you are trying to use dateFormat to handle time, and I wonder if it's necessary to timeFormat instead:

$('#date_with_hours_and_minutes').datetimepicker({
  dateFormat: 'yy.mm.dd',
  timeFormat: 'hh:mm'
});
Sign up to request clarification or add additional context in comments.

2 Comments

Some progress. I am seeing the calendar now, but I am not seeing the time picker.
I'm still not seeing anything other than the date picker
1

either use one of below

change attach event to id: date_with_hours_and_minutes instead of class as you have defined id on the field

 $('.date_with_hours_and_minutes').datetimepicker({
      dateFormat: 'yy-mm-dd'
  })

to

$('#date_with_hours_and_minutes').datetimepicker({
  dateFormat: 'yy-mm-dd'
})

or if you have many datetimepickers on the view

attach class to them

<%= f.text_field :start_date_time, class: "date_with_hours_and_minutes" %>


$('.date_with_hours_and_minutes').datetimepicker({
      dateFormat: 'yy-mm-dd '
});

3 Comments

I fixed the class vs id thing, but I am still only seeing the date picker. No sign of the time picker.
@EastsideDeveloper, did it get fixed?
Adding the # and keeping the id fixes it, but I am still seeing only the date picker (calendar widget), but not the time picker.

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.