From ea08c3aa8174c04a75f9f64eb7dab21fcd728a8c Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Wed, 13 Jan 2021 06:12:14 +0000 Subject: [PATCH] Fix that alerts may be displayed multiple times when the number of files attempting to be uploaded exceeds the limit (#18555). Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@20711 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- public/javascripts/attachments.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/javascripts/attachments.js b/public/javascripts/attachments.js index 76203455e..7e66939d6 100644 --- a/public/javascripts/attachments.js +++ b/public/javascripts/attachments.js @@ -29,8 +29,6 @@ function addFile(inputEl, file, eagerUpload) { addAttachment.toggle(attachmentsFields.children().length < maxFiles); return attachmentId; - } else { - alert($('input.file_selector').data('max-number-of-files-message')); } return null; } @@ -161,6 +159,7 @@ function uploadAndAttachFiles(files, inputEl) { var maxFileSizeExceeded = $(inputEl).data('max-file-size-message'); var sizeExceeded = false; + var filesLength = $(inputEl).closest('.attachments_form').find('.attachments_fields').children().length + files.length $.each(files, function() { if (this.size && maxFileSize != null && this.size > parseInt(maxFileSize)) {sizeExceeded=true;} }); @@ -169,6 +168,10 @@ function uploadAndAttachFiles(files, inputEl) { } else { $.each(files, function() {addFile(inputEl, this, true);}); } + + if (filesLength > ($(inputEl).attr('multiple') == 'multiple' ? 10 : 1)) { + window.alert($(inputEl).data('max-number-of-files-message')); + } return sizeExceeded; } -- 2.39.5