Reputation: 7592
In the jQuery UI datepicker Docs ( http://jqueryui.com/demos/datepicker/ ) it says you can change the default date after init with
$( ".selector" ).datepicker( "option", "defaultDate", +7 );
Where +7 can be a date string, date object, or number of days from today
I can't seem to get this to work. If I set the defaultDate when initializing like this
$(".selector").datepicker({defaultDate:myDateObject});
it works but if I try to use the accessor method I can't get it to work.
Can someone try this and let me know if it works for them and if I've just lost my mind somewhere.
EDIT: Here is a jsFiddle for an example http://jsfiddle.net/Bkw7H/
Upvotes: 4
Views: 10232
Reputation: 4110
I've found that adding options on the load
event of the window
object works when you want to add options to an already initialized datepicker element.
Like so:
function noSundays(date) {
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
if(weekday[date.getDay()] == 'Sunday')
return [false, '', 'Not open on Sundays'];
return [true];
}
jQuery(window).load(function(){
jQuery('.hasDatepicker').datepicker('option', 'maxDate', '+1m +7d');
jQuery('.hasDatepicker').datepicker('option', 'beforeShowDay', noSundays);
});
Upvotes: 1
Reputation: 208002
It's a known bug: http://bugs.jqueryui.com/ticket/6195
Apparently the bug doesn't occur with input elements.
Upvotes: 2