From 6304a7a82a9e9230e5904e355afb6b39549f4efe Mon Sep 17 00:00:00 2001 From: Balazs Endresz Date: Thu, 3 Oct 2024 20:17:47 +0200 Subject: [PATCH] Fix js errors on file list page --- rosetta/static/admin/rosetta/js/rosetta.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/rosetta/static/admin/rosetta/js/rosetta.js b/rosetta/static/admin/rosetta/js/rosetta.js index f13ad5f..9c4dd1b 100644 --- a/rosetta/static/admin/rosetta/js/rosetta.js +++ b/rosetta/static/admin/rosetta/js/rosetta.js @@ -198,7 +198,7 @@ document.addEventListener("DOMContentLoaded", () => { }); // Toggle fuzzy state for all entries on the current page - document.getElementById("action-toggle").addEventListener("change", function () { + document.getElementById("action-toggle")?.addEventListener("change", function () { const checkboxes = document.querySelectorAll('tbody td.c input[type="checkbox"]'); checkboxes.forEach((checkbox) => (checkbox.checked = this.checked)); }); @@ -224,13 +224,15 @@ document.addEventListener("DOMContentLoaded", () => { new FormData(form).forEach((value, key) => (obj[key] = value)); return JSON.stringify(obj); } - const initialDataJson = formToJsonString(); - let isSubmitting = false; - form.addEventListener("submit", () => (isSubmitting = true)); - window.addEventListener("beforeunload", (event) => { - if (!isSubmitting && initialDataJson !== formToJsonString()) { - event.preventDefault(); - event.returnValue = ""; - } - }); + if (form) { + const initialDataJson = formToJsonString(); + let isSubmitting = false; + form.addEventListener("submit", () => (isSubmitting = true)); + window.addEventListener("beforeunload", (event) => { + if (!isSubmitting && initialDataJson !== formToJsonString()) { + event.preventDefault(); + event.returnValue = ""; + } + }); + } });