Replaced the traditional function expressions with ES6 arrow function expressions in the JavaScript for the account form.

This commit is contained in:
依瑪貓 2023-03-04 08:14:05 +08:00
parent e118422441
commit ca86a08f3e

View File

@ -22,7 +22,7 @@
*/ */
// Initializes the page JavaScript. // Initializes the page JavaScript.
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", () => {
initializeBaseAccountSelector(); initializeBaseAccountSelector();
document.getElementById("accounting-base-code") document.getElementById("accounting-base-code")
.onchange = validateBase; .onchange = validateBase;
@ -44,7 +44,7 @@ function initializeBaseAccountSelector() {
const baseContent = document.getElementById("accounting-base-content"); const baseContent = document.getElementById("accounting-base-content");
const options = Array.from(document.getElementsByClassName("accounting-base-option")); const options = Array.from(document.getElementsByClassName("accounting-base-option"));
const btnClear = document.getElementById("accounting-btn-clear-base"); const btnClear = document.getElementById("accounting-btn-clear-base");
selector.addEventListener("show.bs.modal", function () { selector.addEventListener("show.bs.modal", () => {
base.classList.add("accounting-not-empty"); base.classList.add("accounting-not-empty");
for (const option of options) { for (const option of options) {
option.classList.remove("active"); option.classList.remove("active");
@ -54,13 +54,13 @@ function initializeBaseAccountSelector() {
selected.classList.add("active"); selected.classList.add("active");
} }
}); });
selector.addEventListener("hidden.bs.modal", function () { selector.addEventListener("hidden.bs.modal", () => {
if (baseCode.value === "") { if (baseCode.value === "") {
base.classList.remove("accounting-not-empty"); base.classList.remove("accounting-not-empty");
} }
}); });
for (const option of options) { for (const option of options) {
option.onclick = function () { option.onclick = () => {
baseCode.value = option.dataset.code; baseCode.value = option.dataset.code;
baseContent.innerText = option.dataset.content; baseContent.innerText = option.dataset.content;
btnClear.classList.add("btn-danger"); btnClear.classList.add("btn-danger");
@ -70,7 +70,7 @@ function initializeBaseAccountSelector() {
bootstrap.Modal.getInstance(selector).hide(); bootstrap.Modal.getInstance(selector).hide();
}; };
} }
btnClear.onclick = function () { btnClear.onclick = () => {
baseCode.value = ""; baseCode.value = "";
baseContent.innerText = ""; baseContent.innerText = "";
btnClear.classList.add("btn-secondary") btnClear.classList.add("btn-secondary")
@ -92,7 +92,7 @@ function initializeBaseAccountQuery() {
const optionList = document.getElementById("accounting-base-option-list"); const optionList = document.getElementById("accounting-base-option-list");
const options = Array.from(document.getElementsByClassName("accounting-base-option")); const options = Array.from(document.getElementsByClassName("accounting-base-option"));
const queryNoResult = document.getElementById("accounting-base-option-no-result"); const queryNoResult = document.getElementById("accounting-base-option-no-result");
query.addEventListener("input", function () { query.addEventListener("input", () => {
if (query.value === "") { if (query.value === "") {
for (const option of options) { for (const option of options) {
option.classList.remove("d-none"); option.classList.remove("d-none");