Exclude Weekends or Holidays from Calendar Widget in Forms
  • 06 Mar 2026
  • Dark
    Light
  • PDF

Exclude Weekends or Holidays from Calendar Widget in Forms

  • Dark
    Light
  • PDF

Article summary

You can use a calendar widget on a form to capture a date input. You can also restrict the days available to the registrant, for example, to only non-holiday weekdays.

The following code restricts the selection of weekends and holidays (a list that you can modify and maintain), and this code can be modified to restrict selection of other days of the week, too.

In your form:

  1. Ensure that your calendar field has an export label, such as "date".

  2. Select Edit Scripts / Styles.

  3. In the Custom Scripts tab, paste the following:

    var holidays = ['7/4/2016', '12/25/2016'];
    form.getQuestion('date').find('.hasDatepicker').datepicker('option', { beforeShowDay: function(date)
    {
    var show = true;
    if(date.getDay() == 0 || date.getDay() == 6){show = false;} //exclude weekends
    for (var i = 0; i < holidays.length; i++) if (new Date(holidays[i]).toString() == date.toString()) { show = false; break; } //exclude holidays\\
    return [show];
    }});

  4. Select Save.

  5. Test the form to ensure that the calendar days are being disabled as desired.

Example

inline-512538150.png

You only need to reference your export key at the beginning, where it says form.getQuestion(.

All other references to date should remain unchanged:

var holidays = ['7/5/2021', '12/25/2021'];
form.getQuestion('sys:field:callback').find('.hasDatepicker').datepicker('option', { beforeShowDay: function(date)
{
 var show = true;
 if(date.getDay() == 0 || date.getDay() == 6){show = false;} //exclude weekends
 for (var i = 0; i < holidays.length; i++) if (new Date(holidays[i]).toString() == date.toString()) { show = false; break; } //exclude holidays
 return [show];
}});


Was this article helpful?