2010-07-15 6 views
0

J'ai cette réponse de travail, mais je voudrais étendre: jQuery UI Datepicker - Disable specific daysjQueryUI Datepicker noWeekendsAndHolidaysAndWeekDay

Je suis bloqué sur l'ajout de cette méthode à la solution:

beforeShowDay: function(date){ 
     var day = date.getDay(); 
     return [(day != 5)]; 
    } 

à noWeekendsAndHolidays. Comment puis-je ajouter cela?

Ainsi, le datepicker option beforeShowDay aurait 3 retourne "faux":

  1. aucun week-end
  2. pas de vacances
  3. pas en semaine sélectionné («nous sommes fermés le vendredi, trop ")

code de travail avec les deux premières options (j'ai besoin d'aide avec le troisième):

$(document).ready(function(){ 

$("#datepicker").datepicker({ 
    noWeekends: true, 
    numberOfMonths: 2, 
    beforeShowDay: noWeekendsOrHolidays, 
    minDate: '-1M -1W -1D', 
    maxDate: '+1M', 
    firstDay: 1 
}); 


function nationalDays(date){ 
    var natDays = [[7, 26, 'Shop-Closed']]; 
    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; 
    } 
}  
}); 

Merci d'avance.

Répondre

1

Comme ça?

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

function noFridays(date) { 
    var day = date.getDay(); 
    return [(day != 5),""]; 
} 
+0

Oui, exactement. Merci Simen. – orolo

Questions connexes