disabledDateRanges
Sets or gets ranges of dates that a site visitor can't select.
Description
Setting the disabledDateRanges
property prevents site visitors from
selecting dates in the specified ranges.
Set disabledDateRanges
to:
- An array of date ranges to disable, each with a start date and an end date
- An empty array (
[]
), to remove the current disabled dates
Getting the disabledDateRanges
property returns the current
list of disabled date ranges.
Ranges are inclusive. This means that January 10th and February 10th are disabled when specifying a range from January 10, 2025 to February 10, 2025.
Disabled dates override any dates enabled with the enabledDateRanges
property.
This means that if a date matches both enabled and disabled properties, the site visitor
can't select the date in the date picker.
Type:
NAME
TYPE
DESCRIPTION
Start date for the range. The startDate
is inclusive,
meaning it's included in the range. The start date must be earlier than or the same as the
end date of the range.
End date for the range. The endDate
is inclusive,
meaning it's included in the range. The end date must be later than or the same as the
start date of the range.
Related Content:
Was this helpful?
1let disabledDates = $w('#myDatePicker').disabledDateRanges;23let firstDisabledStartDateAsString = disabledDates[0].startDate.toDateString(); // 'Sat Dec 25 2022'
1const holidays2022 = [2 {3 startDate: new Date('4/15/2022'),4 endDate: new Date('4/17/2022')5 },6 {7 startDate: new Date('12/25/2022'),8 endDate: new Date('01/01/2023')9 }10];11$w('#myDatePicker').disabledDateRanges = holidays2022;
This example demonstrates how to base the disabled date ranges on the time zone for a specific country, such as New Zealand, and to take daylight savings into account (GMT+13 instead of GMT+12).
1$w('#myDatePicker').timeZone = 'Pacific/Auckland';23// In 2022, New Zealand switches to daylight savings4// time on September 25th56const disabledDates = [7 {8 startDate: new Date('06/10/2022 GMT+12'),9 endDate: new Date('08/15/2022 GMT+12')10 },11 {12 startDate: new Date('08/01/2022 GMT+12'),13 endDate: new Date('10/01/2022 GMT+13')14 }15];1617$w('#myDatePicker').disabledDateRanges = disabledDates;
This example demonstrates how to:
- Enable certain months in the date picker, such as for an "on call" roster for a team
- Disable holidays
- Disable weekends
1const roster = [2 {3 startDate: new Date('1/1/2022'),4 endDate: new Date('1/31/2022')5 },6 {7 startDate: new Date('4/01/2022'),8 endDate: new Date('4/30/2022')9 },10 {11 startDate: new Date('7/01/2022'),12 endDate: new Date('7/31/2022')13 },14 {15 startDate: new Date('10/01/2022'),16 endDate: new Date('10/31/2022')17 }18];1920const holidays2022 = [21 {22 startDate: new Date('4/15/2022'),23 endDate: new Date('4/17/2022')24 },25 {26 startDate: new Date('12/25/2022'),27 endDate: new Date('01/01/2023')28 }29];3031$w('#myDatePicker').enabledDateRanges = roster; // Available on 1st month of each quarter32$w('#myDatePicker').disabledDateRanges = holidays2022; // Not available on holidays33$w('#myDatePicker').disabledDaysOfWeek = [0, 6]; // Not available on weekends