In a gravity form I have been able to disable weekends and public holidays from Datepicker 1 (from date) and Datepicker 2 (to date).
In Datepicker 2 we want to select the first workday three days after the date selected in Datepicker 1.
See: http://returatrv.staging.wpengine.com/bestilling-container-borettslag/
If you select feb 17 in cal1, feb 20 is selected in DP2, which is correct. The setDate is getDate +3 days.
When setDate ends up on a weekend or disabled date, it should jump to the next work-day. If feb 19 is selected in DP1, feb 24 should be selected in DP2 (first workday). How can I use the code already in place (line 9-15) to set setDate to the first non-disabled day in the array?
I have a feeling I could reuse the code in
optionsObj.beforeShowDay = function(date) { ...
to change the setDate for DP2.
set_date.setDate(set_date.getDate() + 3); //check if the result is in disabled days / weekends
I would really appreciate som help on this ;) Although many other questions are similar (like Add days after date is selected excluding weekends and holidays), I have not been able to solve this.
gform.addFilter('gform_datepicker_options_pre_init', function(optionsObj,
formId, fieldId) {
if (formId == <?php echo $skjemaID; ?> && fieldId == 7) {
// Disable holidays and weekends from datapickers
// Could I use this to find first work-day?
optionsObj.beforeShowDay = function(date) {
// array of holidays from external json-source
currentDate = jQuery.datepicker.formatDate('yy-mm-dd', date),
day = date.getDay();
return [!(disabledDays.indexOf(currentDate) != -1 || day == 0 ||
day == 6)];
};
optionsObj.minDate = 1;
optionsObj.onClose = function(dateText, inst) {
var min_date = $.datepicker.parseDate('dd/mm/yy', dateText),
set_date = $.datepicker.parseDate('dd/mm/yy', dateText),
end_date = $.datepicker.parseDate('dd/mm/yy', dateText);
// set minDate in datepicker 1 to nest day
min_date.setDate(min_date.getDate() + 1);
// Find first workday after 3 days
// Samples of expected behaviour:
// Select feb 10 in dp1 - show feb 13 in dp2
// Select feb 12 in dp1 - show feb 17 in dp2
// Select feb 27 in dp1 - show mar in dp2
set_date.setDate(set_date.getDate() +3);
// Check if set_date is in disabledDays or weekend
// if yes, add a day, check again
// if not, select set_day in datepicker 2
$('#input_<?php echo $skjemaID; ?>_8').datepicker('option',
'minDate', min_date).datepicker('setDate', set_date);
};
}
return optionsObj;
});
Please help me in the right direction; I have been struggling quite some time with this.