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,6 +171,7 @@ 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");
if (monthChooser !== null) {
let start = monthChooser.dataset.start; let start = monthChooser.dataset.start;
this.#monthChooser = new tempusDominus.TempusDominus(monthChooser, { this.#monthChooser = new tempusDominus.TempusDominus(monthChooser, {
restrictions: { restrictions: {
@ -194,6 +195,7 @@ class MonthTab extends TabPlane {
.replaceAll("PERIOD", period); .replaceAll("PERIOD", period);
}); });
} }
}
/** /**
* The tab ID * The tab ID
@ -250,6 +252,7 @@ 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");
if (this.#date !== null) {
this.#date.onchange = () => { this.#date.onchange = () => {
if (this.#validateDate()) { if (this.#validateDate()) {
window.location = chooser.modal.dataset.urlTemplate window.location = chooser.modal.dataset.urlTemplate
@ -257,6 +260,7 @@ class DayTab extends TabPlane {
} }
}; };
} }
}
/** /**
* Validates the date. * Validates the date.
@ -338,6 +342,7 @@ 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");
if (this.#start !== null) {
this.#start.onchange = () => { this.#start.onchange = () => {
if (this.#validateStart()) { if (this.#validateStart()) {
this.#end.min = this.#start.value; this.#end.min = this.#start.value;
@ -358,6 +363,7 @@ class CustomTab extends TabPlane {
} }
}; };
} }
}
/** /**
* Validates the start of the period. * Validates the start of the period.