views:

5929

answers:

2

Is there any (easy) way to set the jQuery UI Datepicker to disallow selection of specific, predetermined days?

I was able to get this approach working, however, it produces a null error which prevents it from displaying in IE.

'natDays[...].0' is null or not an object

Thanks in advance!

UPDATE: Might help if I included some code, right? Anyway, most of this was taken straight from the aforementioned thread:

natDays = [
   [7, 23], [7, 24], [8, 13], [8, 14], 
 ];

 function nationalDays(date) {
   for (i = 0; i < natDays.length; i++) {
    if (date.getMonth() == natDays[i][0] - 1
    && date.getDate() == natDays[i][1]) {
     return [false, natDays[i][2] + '_day'];
    }
   }
  return [true, ''];
 }

 function noWeekendsOrHolidays(date) {
   var noWeekend = $.datepicker.noWeekends(date);
   if (noWeekend[0]) {
    return nationalDays(date);
   } else {
    return noWeekend;
   }
 }


 $(function() { 
  $("#datepicker").datepicker({
   inline: true,
   minDate: new Date(2009, 6, 6), 
   maxDate: new Date(2009, 7, 14), 
   numberOfMonths: 2, 
   hideIfNoPrevNext: true,
   beforeShowDay: $.datepicker.noWeekends,
   altField: '#alternate',
  }); 
 });

Thanks again!

+4  A: 

Have you tried declaring natDays properly with the 'var' keyword in front?

Also - you have an extra comma at the end of your natDays definition.

natDays[i][2] won't work as your the arrays only have 2 items in them - try just ''

Additionally, you'll want to set your beforeShowDay function name correctly - doesn't look like it's even calling your custom function

Hainesy
Hmm... just tried it. No luck. This is the error that IE is returning:'natDays[...].0' is null or not an object
Sam
See my recent edit... it's not defined properly (extra comma)
Hainesy
Okay... I think we're getting somewhere! The extra comma fixed things in IE8. Can you show me what you mean with your second comment though? (I'm a JS novice... can you tell?) Thank you!
Sam
Oh!!! The comma at the end! Now it works perfectly. Thanks!
Sam
Cool glad to have helped
Hainesy
A: 
beforeShowDay: $.datepicker.noWeekends,

will be beforeShowDay: noWeekendsOrHolidays,

my email:[email protected]

allen