javascriptvelo

how to disable specific dates on wix


Question 1) How to disable specific dates on WixCode. Using the datePicker, I would like to disable the Dates Starting from Today and > 4 days away.

2) Also to disable all dates from 9 Months away.

I know the standard set disable looks like this:

let badDate1 = new Date(2017, 0, 13);
let badDate2 = new Date(2017, 9, 13);
$w("#myDatePicker").disabledDates = [badDate1, badDate2];

So how do I accomplish question 1 & 2. Thanks a Mill.


Solution

  • First, calculate the first and last dates that are enabled using standard JavaScript date functions. Then, use the minDate and maxDate properties of the date picker element.

    Something like this:

    const startFromDays = 4;
    const endAtMonths = 9;
    const today = new Date();
    let startDate = new Date(today);
    startDate.setDate(startDate.getDate() + 3);
    let endDate = new Date(today);
    endDate.setMonth(endDate.getMonth() + 9);
    
    $w.onReady(function () {
        $w("#datePicker").minDate = startDate;
        $w("#datePicker").maxDate = endDate;
    });