javascript - Can the jQuery UI Datepicker be made to disable Saturdays and Sundays (and holidays)? -


i use datepicker choosing appointment day. set date range next month. works fine. want exclude saturdays , sundays available choices. can done? if so, how?

there beforeshowday option, takes function called each date, returning true if date allowed or false if not. docs:


beforeshowday

the function takes date parameter , must return array [0] equal true/false indicating whether or not date selectable , 1 equal css class name(s) or '' default presentation. called each day in datepicker before displayed.

display national holidays in datepicker.

$(".selector").datepicker({ beforeshowday: nationaldays})     natdays = [   [1, 26, 'au'], [2, 6, 'nz'], [3, 17, 'ie'],   [4, 27, 'za'], [5, 25, 'ar'], [6, 6, 'se'],   [7, 4, 'us'], [8, 17, 'id'], [9, 7, 'br'],   [10, 1, 'cn'], [11, 22, 'lb'], [12, 12, 'ke'] ];  function nationaldays(date) {     (i = 0; < natdays.length; i++) {       if (date.getmonth() == natdays[i][0] - 1           && date.getdate() == natdays[i][1]) {         return [false, natdays[i][2] + '_day'];       }     }   return [true, '']; } 

one built in function exists, called noweekends, prevents selection of weekend days.

$(".selector").datepicker({ beforeshowday: $.datepicker.noweekends }) 

to combine two, (assuming nationaldays function above):

$(".selector").datepicker({ beforeshowday: noweekendsorholidays})     function noweekendsorholidays(date) {     var noweekend = $.datepicker.noweekends(date);     if (noweekend[0]) {         return nationaldays(date);     } else {         return noweekend;     } } 

update: note of jquery ui 1.8.19, beforeshowday option accepts optional third paremeter, popup tooltip


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -