2014-02-09 64 views
0

所以我在預訂表格上使用它。該表格至少需要填寫2天到今天的日期,這意味着您不能提交少於2天通知的預訂。zebra datepicker - 忽略disabled_dates的方向

$(function() { 
    $('#datepicker').Zebra_DatePicker({ 
    direction: [2, false], 
    disabled_dates: ['* * * 0,6'], 
    first_day_of_week : 0 
    }); 
}); 

今天是星期一至星期四,這一切都很好。如果是星期五 - 2天方向允許用戶選擇星期一(因爲它將殘疾人星期六+星期日計爲天數),但我們需要2個工作日而不僅僅是2天。

任何人有任何方向或變通可能?

回答

0

我把自己的功能拼湊在一起。反饋是歡迎的。

/* 
================================================================================================== 
BookingForm - Datepicker 
================================================================================================== 
*/ 
$(function() { 
    $('#datepicker').Zebra_DatePicker({ 
    direction: [nextWorkingDay(), false], 
    disabled_dates: ['* * * 0,6'], 
    first_day_of_week : 0 
    }); 
}); 

這個日期選擇器代碼調用nextWorkingDay功能

/* This function ensures that there is at least 2 working 
    days before they are able to select a date. Without it 
    calling 2 days buffer in Zebra would include weekends meaning 
    you could lob on Saturday and request Monday - needs to be Tuesday at earliest. 
*/ 
function nextWorkingDay() { 
    var today = new Date(); 
    var dd = today.getDate(); 
    //var mm = today.getMonth(); 
    var month=new Array(); 
    month[0]="January"; 
    month[1]="February"; 
    month[2]="March"; 
    month[3]="April"; 
    month[4]="May"; 
    month[5]="June"; 
    month[6]="July"; 
    month[7]="August"; 
    month[8]="September"; 
    month[9]="October"; 
    month[10]="November"; 
    month[11]="December"; 
    var MMM = month[today.getMonth()]; 
    var yyyy = today.getFullYear(); 
    var theDate = dd+'-'+MMM+'-'+yyyy; 
    //All vars captured to do with todays date 
    //Step through finding weekends 

    var startDate = theDate; //"9-DEC-2011" 
    startDate = new Date(startDate.replace(/-/g, "/")); 
    var endDate = "", noOfDaysToAdd = 2, count = 0; 
    while(count < noOfDaysToAdd){ 
     endDate = new Date(startDate.setDate(startDate.getDate() + 1)); 
     if(endDate.getDay() != 0 && endDate.getDay() != 6){ 
      count++; 
     } 
    } 
    // Weekend found OR not found + 2 day buffer added to the date 
    // Convert new date into bits + add padding to the month for Zebra usage 
    var nextDate = new Date(endDate); 
    var theDay = ("0" + (nextDate.getDate() + 1)).slice(-2); //Add padding to day 
    var theMonth = ("0" + (nextDate.getMonth() + 1)).slice(-2); //Add padding to month 
    var theYear = nextDate.getFullYear(); 
    //Format as required by Zebra 
    var actualStart = theDay+'-'+theMonth+'-'+theYear; 
    return (actualStart); 
}