From de23bb702c195f7693ab90b38d251f49f3f7eb1e Mon Sep 17 00:00:00 2001 From: Omar Ahmed Hassan <98468609+omar-ahmed42@users.noreply.github.com> Date: Fri, 29 Nov 2024 19:31:14 +0200 Subject: [PATCH] Fix allowing multiple files to be dropped onto a single file input (#2359) Fix a bug that allowed multiple files to be dropped onto a single-file input element - Fix a bug that allowed multiple files to be dropped onto a single-file input element by accepting only the first file. --- src/main/resources/static/js/fileInput.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/resources/static/js/fileInput.js b/src/main/resources/static/js/fileInput.js index 4553128d..103226f3 100644 --- a/src/main/resources/static/js/fileInput.js +++ b/src/main/resources/static/js/fileInput.js @@ -47,14 +47,16 @@ function setupFileInput(chooser) { const dt = e.dataTransfer; const files = dt.files; - for (let i = 0; i < files.length; i++) { - allFiles.push(files[i]); + const fileInput = document.getElementById(elementId); + if (fileInput?.hasAttribute("multiple")) { + files.forEach(file => allFiles.push(file)); + } else if (fileInput) { + allFiles = [files[0]]; } const dataTransfer = new DataTransfer(); allFiles.forEach((file) => dataTransfer.items.add(file)); - const fileInput = document.getElementById(elementId); fileInput.files = dataTransfer.files; if (overlay) {