diff --git a/app/assets/javascripts/sitewide/drag_n_drop.js b/app/assets/javascripts/sitewide/drag_n_drop.js
index fe9976776..a47c7830d 100644
--- a/app/assets/javascripts/sitewide/drag_n_drop.js
+++ b/app/assets/javascripts/sitewide/drag_n_drop.js
@@ -352,6 +352,7 @@
fileMaxSizeMb = GLOBAL_CONSTANTS.FILE_MAX_SIZE_MB;
fileMaxSize = fileMaxSizeMb * 1024 * 1024;
for (let i = 0; i < files.length; i += 1) {
+ files[i].uuid = Math.random().toString(36);
droppedFiles.push(files[i]);
}
listItems();
@@ -514,7 +515,7 @@
${I18n.t('assets.drag_n_drop.file_label')}
@@ -548,13 +549,15 @@
}
}
- function removeItemHandler(id) {
- $('[data-item-id="' + id + '"]').off('click').on('click', function(e) {
+ function removeItemHandler(uuid) {
+ $('[data-item-id="' + uuid + '"]').off('click').on('click', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
e.stopPropagation();
let $el = $(this);
- let index = $el.data('item-id');
+ let index = droppedFiles.findIndex((file) => {
+ return file.uuid === $el.data('item-id');
+ });
totalSize -= parseInt(droppedFiles[index].size, 10);
droppedFiles.splice(index, 1);
$el.closest('.panel-result-attachment-new').remove();
@@ -575,7 +578,7 @@
.after(uploadedAssetPreview(droppedFiles[i], i))
.promise()
.done(function() {
- removeItemHandler(i);
+ removeItemHandler(droppedFiles[i].uuid);
});
}
validateTotalSize();
@@ -586,7 +589,9 @@
function init(files) {
fileMaxSizeMb = GLOBAL_CONSTANTS.FILE_MAX_SIZE_MB;
fileMaxSize = fileMaxSizeMb * 1024 * 1024;
+
for (let i = 0; i < files.length; i += 1) {
+ files[i].uuid = Math.random().toString(36);
droppedFiles.unshift(files[i]);
}
listItems();