Fix delete button appears on failed uploads
authorjoshuaruesweg <ruesweg@woltlab.com>
Sat, 2 Jul 2022 12:04:43 +0000 (14:04 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Sat, 2 Jul 2022 12:04:43 +0000 (14:04 +0200)
ts/WoltLabSuite/Core/Ui/File/Delete.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/File/Delete.js

index 4a7898dce10cc02555849e8f1eb2274ff66fa8f3..d5d0646f786df71ab61fb0221bdbd81057e435fa 100644 (file)
@@ -70,8 +70,12 @@ class UiFileDelete implements AjaxCallbackObject {
   private createButtons(): void {
     let triggerChange = false;
     this.target.querySelectorAll("li.uploadedFile").forEach((element: HTMLElement) => {
-      const uniqueFileId = element.dataset.uniqueFileId!;
-      if (this.containers.has(uniqueFileId)) {
+      const uniqueFileId = element.dataset.uniqueFileId;
+
+      // If the uniqueFileId is undefined, the upload has not succeded. For non succeded uploads
+      // we do not want a delete button, because the file is cleared automatically
+      // with the next upload.
+      if (uniqueFileId === undefined || this.containers.has(uniqueFileId)) {
         return;
       }
 
index 9e1ae00ff0a44379ae33a549006c48da51118128..ee731ff2a31507caf435a2ddf034bb3cb1ec47e9 100644 (file)
@@ -44,7 +44,10 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch
             let triggerChange = false;
             this.target.querySelectorAll("li.uploadedFile").forEach((element) => {
                 const uniqueFileId = element.dataset.uniqueFileId;
-                if (this.containers.has(uniqueFileId)) {
+                // If the uniqueFileId is undefined, the upload has not succeded. For non succeded uploads
+                // we do not want a delete button, because the file is cleared automatically
+                // with the next upload.
+                if (uniqueFileId === undefined || this.containers.has(uniqueFileId)) {
                     return;
                 }
                 const elementData = {