Allow the function `get values()` to return only one number for single file upload...
authorCyperghost <olaf_schmitz_1@t-online.de>
Tue, 2 Jul 2024 08:30:22 +0000 (10:30 +0200)
committerCyperghost <olaf_schmitz_1@t-online.de>
Tue, 2 Jul 2024 08:30:22 +0000 (10:30 +0200)
ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts
ts/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.js

index ba6c4d2af9b9e5e46f1c526fe16c6a3fb4f51ff7..963ae979f17f419a6acb47d05a61b47b3d0d57c5 100644 (file)
@@ -354,7 +354,16 @@ export class FileProcessor {
     this.addButtons(container, element);
   }
 
-  get values(): Set<number> {
+  get values(): undefined | number | Set<number> {
+    if (this.#singleFileUpload) {
+      const input = this.#container.querySelector<HTMLInputElement>('input[type="hidden"]');
+      if (input === null) {
+        return undefined;
+      }
+
+      return parseInt(input.value, 10);
+    }
+
     return new Set(
       Array.from(this.#container.querySelectorAll<HTMLInputElement>('input[type="hidden"]')).map((input) =>
         parseInt(input.value, 10),
@@ -363,7 +372,7 @@ export class FileProcessor {
   }
 }
 
-export function getValues(fieldId: string): Set<number> {
+export function getValues(fieldId: string): undefined | number | Set<number> {
   const field = _data.get(fieldId);
   if (field === undefined) {
     throw new Error("Unknown field with id '" + fieldId + "'");
index 5dc1da71c1d774d350b81bee4a707f8b35db11bd..3a14e664e69d3c2ff899c59bcd40d1e44a39c190 100644 (file)
@@ -13,8 +13,13 @@ import { getValues } from "WoltLabSuite/Core/Form/Builder/Field/Controller/FileP
 
 export default class FileProcessor extends Field {
   protected _getData(): FormBuilderData {
+    const value = getValues(this._fieldId);
+    if (value === undefined) {
+      return {};
+    }
+
     return {
-      [this._fieldId]: getValues(this._fieldId),
+      [this._fieldId]: value,
     };
   }
 
index 38ab23cd938115c5050dc7033ca29f2b18c497fc..af8bccc5778171389d88495244f8065061d561a9 100644 (file)
@@ -292,6 +292,13 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Language", "WoltLabSui
             this.addButtons(container, element);
         }
         get values() {
+            if (this.#singleFileUpload) {
+                const input = this.#container.querySelector('input[type="hidden"]');
+                if (input === null) {
+                    return undefined;
+                }
+                return parseInt(input.value, 10);
+            }
             return new Set(Array.from(this.#container.querySelectorAll('input[type="hidden"]')).map((input) => parseInt(input.value, 10)));
         }
     }
index 242e56508c764fe64eb19513e8ebb609debcf5a8..8549cc4859c07940a26e496c3f08a1ad73738b72 100644 (file)
@@ -12,8 +12,12 @@ define(["require", "exports", "tslib", "WoltLabSuite/Core/Form/Builder/Field/Fie
     Field_1 = tslib_1.__importDefault(Field_1);
     class FileProcessor extends Field_1.default {
         _getData() {
+            const value = (0, FileProcessor_1.getValues)(this._fieldId);
+            if (value === undefined) {
+                return {};
+            }
             return {
-                [this._fieldId]: (0, FileProcessor_1.getValues)(this._fieldId),
+                [this._fieldId]: value,
             };
         }
         _readField() {