TODO: optimise and fix bug

This commit is contained in:
David Cook
2024-03-25 15:59:59 +11:00
parent 4ddb2ff1e9
commit d238fc0cad

View File

@@ -55,6 +55,7 @@ export default class BulkFormController extends Controller {
toggleFormChanged() {
// For each record, check if any fields are changed
// TODO: optimise basd on current state. if field is changed, but form already changed, no need to update (and vice versa)
const changedRecordCount = Object.values(this.recordElements).filter((elements) =>
elements.some(this.#isChanged)
).length;
@@ -73,7 +74,7 @@ export default class BulkFormController extends Controller {
// Prevent accidental data loss
if (formChanged) {
window.addEventListener("beforeunload", this.preventLeavingBulkForm);
window.addEventListener("beforeunload", this.preventLeavingBulkForm); // TOFIX: what if it has laredy been added? we can optimise above to avoid this
} else {
window.removeEventListener("beforeunload", this.preventLeavingBulkForm);
}