How to Restrict the calendar/datepicker minimum date to +x business days
The popup calendar can be restricted to show a minimum date, based on business days only using a little custom javascript, executed when the form loads. We can create an action on the forms root node (these actions will run when the form loads), and call it to modify one of the properties of the pop up calendar.
Here are the steps:
- Click on the name of your form in the outline panel in the Form Designer
- Find and click on actions in the General Settings Property Panel
- Create a new Action and choose Custom JavaScript
- Give the action a name, and click next.
- Enter the following code, but replace "End Date" with the name of your field (the name must match exactly and IS case sensitive)
// This function will receive the field and form objects. function(field,form){ // get the calendar, the field name must match your field name exactly var datepicker = form.getFieldByName('StartDate').getDatePicker(); var workingDays = new Date(), workingDaysNum = 4; // this is the minimum number of days var adjustments = [0, 0, 2, 2, 2, 2, 1]; // Offsets by day of the week workingDays.setDate(workingDays.getDate() + workingDaysNum + adjustments[workingDays.getDay()]); datepicker.settings.minDate = workingDays datepicker.settings.beforeShowDay = $.datepicker.noWeekends; }
Save your changes and test your form. When you open the calendar, weekends should now be grayed out.
Have more questions? Submit a request
Please sign in to leave a comment.
0 Comments