From 74e5b5d1c745b544dbac5fb3fb01034fbf990469 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Tue, 8 Nov 2022 18:39:23 -0600 Subject: [PATCH] Stop creating multiple error dialogs --- src/main/resources/public/js/main.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/resources/public/js/main.js b/src/main/resources/public/js/main.js index 312fd55..0baeec2 100644 --- a/src/main/resources/public/js/main.js +++ b/src/main/resources/public/js/main.js @@ -74,12 +74,14 @@ const submitForm = () => { }) .then((res) => { if (!res.ok) { - controls = document.querySelector(".pure-controls"); - errBox = document.createElement("p"); - errBox.setAttribute("id", "errBox"); - errBox.setAttribute("style", "color:red"); - errBox.innerHTML = "Short URL not valid or already in use"; - controls.appendChild(errBox); + if (document.getElementById("errBox") == null) { + controls = document.querySelector(".pure-controls"); + errBox = document.createElement("p"); + errBox.setAttribute("id", "errBox"); + errBox.setAttribute("style", "color:red"); + errBox.innerHTML = "Short URL not valid or already in use!"; + controls.appendChild(errBox); + } } else { document.getElementById("errBox")?.remove();