albertopq / jquery_datepicker

Rails 3 plugin that allows you to select dates from a calendar
91 stars 60 forks source link

How to use onSelect #27

Closed ghost closed 12 years ago

ghost commented 12 years ago

I can see how to pass options, but how can I add a onSelect function?

What I would like to add:

onSelect: (selectedDate) ->
  $("#to").datetimepicker "option", "minDate", selectedDate

Add to the line:

<%= f.datetime_picker :to, maxDate: "0", changeMonth: "true", changeYear: "true" %>

house9 commented 12 years ago

i have done it like this with datepicker - guessing it would be the same with datetimepicker? your coffeescript would look something like this

    # date picker selected callback
    onSelectMethod = (dateText, inst) ->
      $("#to").datetimepicker "option", "minDate", dateText

    # bind to date picker 
    $('#to').datetimepicker('option', 'onSelect', onSelectMethod)

http://jqueryui.com/demos/datepicker/#event-onSelect

ghost commented 12 years ago

Thanks for your response but I solved my problem. I wasn't thinking about it correctly, I was wondering if you could pass the onSelect on the line:

<%= f.datetime_picker :to, maxDate: "0", changeMonth: "true", changeYear: "true" %>

But all you need to do is give it an id like so:

<%= f.datetime_picker :to, id: "myToDatePicker" %>

Then in coffescript/javascript you can reference it as so:

$("#myToDatePicker").datetimepicker