From 43d34a740fabb2375c919f6aa1b4fbfdcd68b0b4 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Tue, 12 Nov 2024 15:50:11 -0600 Subject: [PATCH] For overrides fallback to the class value when an override is deleted. --- htdocs/js/DatePicker/datepicker.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/htdocs/js/DatePicker/datepicker.js b/htdocs/js/DatePicker/datepicker.js index 3690415b72..e7d01f365a 100644 --- a/htdocs/js/DatePicker/datepicker.js +++ b/htdocs/js/DatePicker/datepicker.js @@ -43,9 +43,10 @@ ).getTime(); for (const rule of groupRules) { - const value = - rule[0].value || document.getElementsByName(`${rule[0].name}.class_value`)[0]?.dataset.classValue; + const classValue = document.getElementsByName(`${rule[0].name}.class_value`)[0]?.dataset.classValue; + const value = rule[0].value || classValue; rule.push(value ? parseInt(value) * 1000 - timezoneAdjustment : 0); + if (classValue) rule.push(parseInt(classValue) * 1000 - timezoneAdjustment); } const update = (input) => { @@ -53,16 +54,25 @@ if (activeIndex == -1) return; const activeFieldDate = groupRules[activeIndex][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || + groupRules[activeIndex][2] || groupRules[activeIndex][1]; for (let i = 0; i < groupRules.length; ++i) { if (i == activeIndex) continue; const thisFieldDate = - groupRules[i][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || groupRules[i][1]; + groupRules[i][0]?.parentNode._flatpickr.selectedDates[0]?.getTime() || + groupRules[i][2] || + groupRules[i][1]; if (i < activeIndex && thisFieldDate > activeFieldDate) - groupRules[i][0].parentNode._flatpickr.setDate(activeFieldDate, true); + groupRules[i][0].parentNode._flatpickr.setDate( + activeFieldDate === groupRules[i][2] ? undefined : activeFieldDate, + true + ); else if (i > activeIndex && thisFieldDate < activeFieldDate) - groupRules[i][0].parentNode._flatpickr.setDate(activeFieldDate, true); + groupRules[i][0].parentNode._flatpickr.setDate( + activeFieldDate === groupRules[i][2] ? undefined : activeFieldDate, + true + ); } };