Skip to content

Commit

Permalink
For overrides fallback to the class value when an override is deleted.
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrice1 committed Nov 12, 2024
1 parent c02f04a commit fc659e1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions htdocs/js/DatePicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,36 @@
).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) => {
const activeIndex = groupRules.findIndex((r) => r[0] === input);
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
);
}
};

Expand Down

0 comments on commit fc659e1

Please sign in to comment.