albertopq / jquery_datepicker

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

minDate format "new Date(miliseconds)" not supported? #32

Open JeanMertz opened 11 years ago

JeanMertz commented 11 years ago

It seems when I do:

= f.datepicker :expire, dateFormat: 'dd-mm-yy', minDate: 'new Date()'

Things work correctly (that is, I can't go lower than todays date)

However, this doesn't work:

= f.datepicker :expire, dateFormat: 'dd-mm-yy', minDate: 'new Date(1289430000000)'

This time, I shouldn't be able to go lower than "11-11-2010" but I still can.

I verified that this should work by using the following, which worked correctly:

:javascript
  $( "#datepicker" ).datepicker({ minDate: new Date(1289430000000) });

Any idea what might be going on here?

JeanMertz commented 11 years ago

Thinking some more about this (after being head down on this issue for the past two hours) I just realize that it could be because the javascript doesn't get evaluated and so only hard values work here? (like -10 or "+1W"). But then why would new Date() work but new Date(1289430000000) won't?

So, the question then remains, can I set fixed min/max date instead of a relative date using this gem? (all examples in the README show relative date ranges)

albertopq commented 11 years ago

Hi! The point is that parameter is meant to be in javascript, but we are passing it through Rails. The plugin doesn't support evaluating the javascript (at least, it doesn't yet). In fact, new Date() isn't working either, if you set whatever string you want you'll se the same result.

You can use other options instead a Date object:

http://api.jqueryui.com/datepicker/#option-minDate

I would suggest using a string following the dateFormat ('26-06-2013', if your dateFormat is dd-mm-yy, for example)

So,

= f.datepicker :expire, dateFormat: 'dd-mm-yy', minDate: '26-06-2013'

should work. I'll add some clarifications in the README file.

Let me know if that helps. Thanks!