views:

303

answers:

3

jQueryUI Datepicker documentation states that the minDate option can be set using "a string in the current dateFormat". So I've tried the following to initialize datepickers:

$("input.date").datepicker({ minDate: "01/01/2010", maxDate: "12/31/2010" });

However, this results in my datepicker having a selectable date range that goes from 11/06/2015 to 12/17/2015.

I've checked the current dateformat and its mm/dd/yy, which is supposed to mean 2 digits for the month, 2 for the day, and 4 for the year, separated by slashes. I've also tried including dateFormat: "mm/dd/yy" in the inizialization statement.

I've also checked the values for minDate and maxDate afterwards and they ARE being set to the values I want: 01/01/2010 and 12/31/2010.

I want to be able to set min/maxDate with strings because I'm being passed these values as strings from somewhere else. Maybe someone knows why this happens and how to solve this, or a workaround to achieve this, perphaps changing the format of the date strings or something?

Thanks

EDIT: Using: jQuery v1.3.2 and jQuery UI v1.7.2

A: 

Appears to be a "bug" in 1.3.2 with 1.7.2. In 1.4.2 with 1.8.1 all is fine.

Dratted bugs... And I couldn't update to the latest versions just like that...
leo
A: 

In the end I had to use something like this, since the v1.7 datepicker has no probs with Dates:

$.getJSON("/GetMinMaxDates/", function(dates) {
    var DateLimits = {min:null, max:null};

    DateLimits.min = new Date(Date.parse(dates.min));
    DateLimits.max = new Date(Date.parse(dates.max));

    $("input.date").datepicker({ dateFormat: "mm/dd/yy", minDate: DateLimits.min, maxDate: DateLimits.max });
});
leo
A: 

I found your last method to be best for IE7/8 anyway. IE returns NaN in string-fed Date functions; as soon as I parsed to numbers the problem disappeared.

John Burgoon