From fbbc71d7e6a3fe81fb1dbcdca3556a18d1a21798 Mon Sep 17 00:00:00 2001 From: t71rs <166131967+t71rs@users.noreply.github.com> Date: Fri, 3 May 2024 20:09:36 +0200 Subject: [PATCH] Drag&drop bug (#1157) * Fixed issue that Drag and Droppped Files can not be deleted * Deleted unnecessary Comment --- src/main/resources/static/js/fileInput.js | 5 +++++ src/main/resources/static/js/merge.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/main/resources/static/js/fileInput.js b/src/main/resources/static/js/fileInput.js index 89ad1ad9..001c8f24 100644 --- a/src/main/resources/static/js/fileInput.js +++ b/src/main/resources/static/js/fileInput.js @@ -104,4 +104,9 @@ function setupFileInput(chooser) { $(inputElement).siblings(".custom-file-label").addClass("selected").html(pdfPrompt); } } + //Listen for event of file being removed and the filter it out of the allFiles array + document.addEventListener("fileRemoved", function (e) { + const fileName = e.detail; + allFiles = allFiles.filter(file => file.name !== fileName); + }); } diff --git a/src/main/resources/static/js/merge.js b/src/main/resources/static/js/merge.js index 4936fa6b..55575727 100644 --- a/src/main/resources/static/js/merge.js +++ b/src/main/resources/static/js/merge.js @@ -69,8 +69,13 @@ function attachMoveButtons() { removeButtons[i].addEventListener("click", function (event) { event.preventDefault(); var parent = this.closest(".list-group-item"); + //Get name of removed file + var fileName = parent.querySelector(".filename").innerText; parent.remove(); updateFiles(); + //Dispatch a custom event with the name of the removed file + var event = new CustomEvent("fileRemoved", { detail: fileName }); + document.dispatchEvent(event); }); } }