Fixed the JavaScript period chooser error when there is no data.

This commit is contained in:
依瑪貓 2023-03-09 22:25:26 +08:00
parent af71874f9d
commit 7feb6da062

View File

@ -171,28 +171,30 @@ class MonthTab extends TabPlane {
constructor(chooser) { constructor(chooser) {
super(chooser); super(chooser);
const monthChooser = document.getElementById(this.prefix + "-chooser"); const monthChooser = document.getElementById(this.prefix + "-chooser");
let start = monthChooser.dataset.start; if (monthChooser !== null) {
this.#monthChooser = new tempusDominus.TempusDominus(monthChooser, { let start = monthChooser.dataset.start;
restrictions: { this.#monthChooser = new tempusDominus.TempusDominus(monthChooser, {
minDate: start, restrictions: {
}, minDate: start,
display: {
inline: true,
components: {
date: false,
clock: false,
}, },
}, display: {
defaultDate: monthChooser.dataset.default, inline: true,
}); components: {
monthChooser.addEventListener(tempusDominus.Namespace.events.change, (e) => { date: false,
const date = e.detail.date; clock: false,
const year = date.year; },
const month = date.month + 1; },
const period = month < 10? year + "-0" + month: year + "-" + month; defaultDate: monthChooser.dataset.default,
window.location = chooser.modal.dataset.urlTemplate });
.replaceAll("PERIOD", period); monthChooser.addEventListener(tempusDominus.Namespace.events.change, (e) => {
}); const date = e.detail.date;
const year = date.year;
const month = date.month + 1;
const period = month < 10? year + "-0" + month: year + "-" + month;
window.location = chooser.modal.dataset.urlTemplate
.replaceAll("PERIOD", period);
});
}
} }
/** /**
@ -250,12 +252,14 @@ class DayTab extends TabPlane {
super(chooser); super(chooser);
this.#date = document.getElementById(this.prefix + "-date"); this.#date = document.getElementById(this.prefix + "-date");
this.#dateError = document.getElementById(this.prefix + "-date-error"); this.#dateError = document.getElementById(this.prefix + "-date-error");
this.#date.onchange = () => { if (this.#date !== null) {
if (this.#validateDate()) { this.#date.onchange = () => {
window.location = chooser.modal.dataset.urlTemplate if (this.#validateDate()) {
.replaceAll("PERIOD", this.#date.value); window.location = chooser.modal.dataset.urlTemplate
} .replaceAll("PERIOD", this.#date.value);
}; }
};
}
} }
/** /**
@ -338,25 +342,27 @@ class CustomTab extends TabPlane {
this.#end = document.getElementById(this.prefix + "-end"); this.#end = document.getElementById(this.prefix + "-end");
this.#endError = document.getElementById(this.prefix + "-end-error"); this.#endError = document.getElementById(this.prefix + "-end-error");
this.#conform = document.getElementById(this.prefix + "-confirm"); this.#conform = document.getElementById(this.prefix + "-confirm");
this.#start.onchange = () => { if (this.#start !== null) {
if (this.#validateStart()) { this.#start.onchange = () => {
this.#end.min = this.#start.value; if (this.#validateStart()) {
} this.#end.min = this.#start.value;
}; }
this.#end.onchange = () => { };
if (this.#validateEnd()) { this.#end.onchange = () => {
this.#start.max = this.#end.value; if (this.#validateEnd()) {
} this.#start.max = this.#end.value;
}; }
this.#conform.onclick = () => { };
let isValid = true; this.#conform.onclick = () => {
isValid = this.#validateStart() && isValid; let isValid = true;
isValid = this.#validateEnd() && isValid; isValid = this.#validateStart() && isValid;
if (isValid) { isValid = this.#validateEnd() && isValid;
window.location = chooser.modal.dataset.urlTemplate if (isValid) {
.replaceAll("PERIOD", this.#start.value + "-" + this.#end.value); window.location = chooser.modal.dataset.urlTemplate
} .replaceAll("PERIOD", this.#start.value + "-" + this.#end.value);
}; }
};
}
} }
/** /**