Replaced the forEach loops with the for-of loops in the JavaScript for the currency form, account form, and the drag-and-drop reorder library functions.
This commit is contained in:
parent
bb7e9e94ee
commit
08dc24605d
@ -46,9 +46,9 @@ function initializeBaseAccountSelector() {
|
|||||||
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", function () {
|
||||||
base.classList.add("accounting-not-empty");
|
base.classList.add("accounting-not-empty");
|
||||||
options.forEach(function (item) {
|
for (const option of options) {
|
||||||
item.classList.remove("active");
|
option.classList.remove("active");
|
||||||
});
|
}
|
||||||
const selected = document.getElementById("accounting-base-option-" + baseCode.value);
|
const selected = document.getElementById("accounting-base-option-" + baseCode.value);
|
||||||
if (selected !== null) {
|
if (selected !== null) {
|
||||||
selected.classList.add("active");
|
selected.classList.add("active");
|
||||||
@ -59,7 +59,7 @@ function initializeBaseAccountSelector() {
|
|||||||
base.classList.remove("accounting-not-empty");
|
base.classList.remove("accounting-not-empty");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
options.forEach(function (option) {
|
for (const option of options) {
|
||||||
option.onclick = function () {
|
option.onclick = function () {
|
||||||
baseCode.value = option.dataset.code;
|
baseCode.value = option.dataset.code;
|
||||||
baseContent.innerText = option.dataset.content;
|
baseContent.innerText = option.dataset.content;
|
||||||
@ -69,7 +69,7 @@ function initializeBaseAccountSelector() {
|
|||||||
validateBase();
|
validateBase();
|
||||||
bootstrap.Modal.getInstance(selector).hide();
|
bootstrap.Modal.getInstance(selector).hide();
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
btnClear.onclick = function () {
|
btnClear.onclick = function () {
|
||||||
baseCode.value = "";
|
baseCode.value = "";
|
||||||
baseContent.innerText = "";
|
baseContent.innerText = "";
|
||||||
@ -94,15 +94,15 @@ function initializeBaseAccountQuery() {
|
|||||||
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", function () {
|
||||||
if (query.value === "") {
|
if (query.value === "") {
|
||||||
options.forEach(function (option) {
|
for (const option of options) {
|
||||||
option.classList.remove("d-none");
|
option.classList.remove("d-none");
|
||||||
});
|
}
|
||||||
optionList.classList.remove("d-none");
|
optionList.classList.remove("d-none");
|
||||||
queryNoResult.classList.add("d-none");
|
queryNoResult.classList.add("d-none");
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let hasAnyMatched = false;
|
let hasAnyMatched = false;
|
||||||
options.forEach(function (option) {
|
for (const option of options) {
|
||||||
const queryValues = JSON.parse(option.dataset.queryValues);
|
const queryValues = JSON.parse(option.dataset.queryValues);
|
||||||
let isMatched = false;
|
let isMatched = false;
|
||||||
for (const queryValue of queryValues) {
|
for (const queryValue of queryValues) {
|
||||||
@ -117,7 +117,7 @@ function initializeBaseAccountQuery() {
|
|||||||
} else {
|
} else {
|
||||||
option.classList.add("d-none");
|
option.classList.add("d-none");
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
if (!hasAnyMatched) {
|
if (!hasAnyMatched) {
|
||||||
optionList.classList.add("d-none");
|
optionList.classList.add("d-none");
|
||||||
queryNoResult.classList.remove("d-none");
|
queryNoResult.classList.remove("d-none");
|
||||||
|
@ -65,9 +65,9 @@ function validateForm() {
|
|||||||
*/
|
*/
|
||||||
function submitFormIfAllAsyncValid() {
|
function submitFormIfAllAsyncValid() {
|
||||||
let isValid = true;
|
let isValid = true;
|
||||||
Object.keys(isAsyncValid).forEach(function (key) {
|
for (const key of Object.keys(isAsyncValid)) {
|
||||||
isValid = isAsyncValid[key] && isValid;
|
isValid = isAsyncValid[key] && isValid;
|
||||||
});
|
}
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
document.getElementById("accounting-form").submit()
|
document.getElementById("accounting-form").submit()
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ function initializeDragAndDropReordering(list, onReorder) {
|
|||||||
function initializeMouseDragAndDropReordering(list, onReorder) {
|
function initializeMouseDragAndDropReordering(list, onReorder) {
|
||||||
const items = Array.from(list.children);
|
const items = Array.from(list.children);
|
||||||
let dragged = null;
|
let dragged = null;
|
||||||
items.forEach(function (item) {
|
for (const item of items) {
|
||||||
item.draggable = true;
|
item.draggable = true;
|
||||||
item.addEventListener("dragstart", function () {
|
item.addEventListener("dragstart", function () {
|
||||||
dragged = item;
|
dragged = item;
|
||||||
@ -56,7 +56,7 @@ function initializeMouseDragAndDropReordering(list, onReorder) {
|
|||||||
dragged.classList.remove("accounting-dragged");
|
dragged.classList.remove("accounting-dragged");
|
||||||
dragged = null;
|
dragged = null;
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,7 +68,7 @@ function initializeMouseDragAndDropReordering(list, onReorder) {
|
|||||||
*/
|
*/
|
||||||
function initializeTouchDragAndDropReordering(list, onReorder) {
|
function initializeTouchDragAndDropReordering(list, onReorder) {
|
||||||
const items = Array.from(list.children);
|
const items = Array.from(list.children);
|
||||||
items.forEach(function (item) {
|
for (const item of items) {
|
||||||
item.addEventListener("touchstart", function () {
|
item.addEventListener("touchstart", function () {
|
||||||
item.classList.add("accounting-dragged");
|
item.classList.add("accounting-dragged");
|
||||||
});
|
});
|
||||||
@ -81,7 +81,7 @@ function initializeTouchDragAndDropReordering(list, onReorder) {
|
|||||||
item.addEventListener("touchend", function () {
|
item.addEventListener("touchend", function () {
|
||||||
item.classList.remove("accounting-dragged");
|
item.classList.remove("accounting-dragged");
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user