Exclude beforeShowDay when defining minDate

I use beforeShowDay to exclude holidays and weekends, however I want beforeShowDays to be excluded when calculating minDate.

eg. if the current day of the week is Friday and minDate is 2, I want the weekend to be excluded from the equation. So instead of being the first date you can choose on Monday, I want it to be on Wednesday.

This is my jQuery:

$( "#date" ).datepicker({
minDate: 2, maxDate: "+12M", // Date range
beforeShowDay: nonWorkingDates
});

Does anyone know how to do this?

+3
source share
1 answer

How about something like this:

function includeDate(date) {
    return date.getDay() !== 6 && date.getDay() !== 0;
}

function getTomorrow(date) {
    return new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1);
}

$("#date").datepicker({
    beforeShowDay: function(date) {
        return [includeDate(date)];
    },
    minDate: (function(min) {
        var today = new Date();
        var nextAvailable = getTomorrow(today);
        var count = 0;
        var newMin = 0; // Modified 'min' value

        while(count < min) {
            if (includeDate(nextAvailable)) {
                count++;
            }
            newMin++; // Increase the new minimum
            nextAvailable = getTomorrow(nextAvailable);            
        }
        return newMin;
    })(2) // Supply with the default minimum value.
});

, , , , beforeShowDay. ( ), 2 4: 2 ( ) 2, .

, , , , .

: http://jsfiddle.net/TpSLC/

+2

All Articles