在重力形式中,我已经能够从DatePicker1(开始日期)和DatePicker2(到日期)禁用周末和公共假日。
在日期选择器2中,我们希望选择日期选择器1中所选日期三天后的第一个工作日。
请参阅:http://returatrv.staging.wpengine.com/bestilling-container-borettslag/
如果在cal1中选择feb 17,则在DP2中选择feb 20,这是正确的。setDate是getDate +3天。
当setDate在周末或残疾日期结束时,它应该跳到下一个工作日。如果在DP1中选择了feb 19,则在DP2 (第一个工作日)中应选择feb 24。如何使用已有的代码(第9-15行)将setDate设置为数组中的第一个非禁用日期?
我有一种感觉,我可以在
optionsObj.beforeShowDay = function(date) { ...
更改DP2的setDate。
set_date.setDate(set_date.getDate() + 3); //check if the result is in disabled days / weekends
我真的很感谢在这方面的一些帮助;)尽管许多其他问题类似(如Add days after date is selected excluding weekends and holidays),但我无法解决这个问题。
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;
});
请帮助我找到正确的方向,我已经为此挣扎了很长时间。
转载请注明出处:http://www.shandongyidao.com/article/20230526/2386626.html