Skip to content

Commit

Permalink
Initial poke at validation for leap days. Might need a rethink.
Browse files Browse the repository at this point in the history
  • Loading branch information
V13Axel committed Nov 17, 2024
1 parent 8aae17f commit 0fe6c52
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions resources/js/calendar/leap_days_collapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,23 @@ class LeapDaysCollapsible extends CollapsibleComponent {
}

validators = {
"leap_days": this.validateLeapDayInterval
"leap_days": this.validateLeapDayIntervals.bind(this)
};

validateLeapDayInterval() {

validateLeapDayIntervals() {
for (let leapDay of this.leap_days) {

let { interval } = leapDay;

interval = interval.replace(/,\s*$/, "");

if (interval === "0") {
// TODO: Add proper error messaging to outer components, and prevent re-render
// `${leapDay.name}'s interval is 0, please enter a positive number.`
return;
return { error: true, message: `${leapDay.name}'s interval is 0, please enter a positive number.` };
}

let invalid = this.interval_wide_regex.test(interval);

if (invalid) {
// TODO: Add proper error messaging to outer components, and prevent re-render
// `${leapDay.name} has an invalid interval formula.`
return;
return { error: true, message: `${leapDay.name} has an invalid interval formula.` };
}

let values = interval.split(',');
Expand All @@ -90,9 +84,7 @@ class LeapDaysCollapsible extends CollapsibleComponent {
}

if (invalid) {
// TODO: Add proper error messaging to outer components, and prevent re-render
// `${leapDay.name} has an invalid interval formula. Plus before exclamation point.` : '');
return;
return { error: true, message: `${leapDay.name} has an invalid interval formula. The plus goes before the exclamation point.` };
}

let unsorted = [];
Expand All @@ -117,9 +109,13 @@ class LeapDaysCollapsible extends CollapsibleComponent {
leapDay.interval = result.join(',');
}

// TODO: Persist sorted value somehow
}

getLeapDayIntervalText(leapDay) {
if (!this.is_valid) {
return "Error detected.";
}

let values = leapDay.interval.split(',').reverse();
let sorted = [];
Expand Down

0 comments on commit 0fe6c52

Please sign in to comment.