From: Cyperghost Date: Tue, 2 Jul 2024 08:30:22 +0000 (+0200) Subject: Allow the function `get values()` to return only one number for single file upload... X-Git-Tag: 6.1.0_Alpha_1~41^2~14 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d5c6a09981cbdc136f8f68d384e53f0530b7de6d;p=GitHub%2FWoltLab%2FWCF.git Allow the function `get values()` to return only one number for single file upload and also `undefined` if no file is uploaded --- diff --git a/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts b/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts index ba6c4d2af9..963ae979f1 100644 --- a/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts +++ b/ts/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.ts @@ -354,7 +354,16 @@ export class FileProcessor { this.addButtons(container, element); } - get values(): Set { + get values(): undefined | number | Set { + 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), @@ -363,7 +372,7 @@ export class FileProcessor { } } -export function getValues(fieldId: string): Set { +export function getValues(fieldId: string): undefined | number | Set { const field = _data.get(fieldId); if (field === undefined) { throw new Error("Unknown field with id '" + fieldId + "'"); diff --git a/ts/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.ts b/ts/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.ts index 5dc1da71c1..3a14e664e6 100644 --- a/ts/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.ts +++ b/ts/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.ts @@ -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, }; } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js index 38ab23cd93..af8bccc577 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Controller/FileProcessor.js @@ -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))); } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.js index 242e56508c..8549cc4859 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/FileProcessor.js @@ -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() {