From bff3d7ab50fbc25d5a99feb94fd0f04ed8b004d6 Mon Sep 17 00:00:00 2001 From: MysteryCode Date: Mon, 14 Jun 2021 07:23:27 +0200 Subject: [PATCH] Fix reading i18n data from form builder forms (#4284) Previous the code caused the following error: `Uncaught TypeError: Cannot set property '1' of undefined` since it tries to set the language's value in an object which doesn't exist (yet). --- ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts | 4 ++++ .../js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts b/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts index 8cafa4b2ea..20b083f045 100644 --- a/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts +++ b/ts/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.ts @@ -20,6 +20,10 @@ class ValueI18n extends Field { const values = LanguageInput.getValues(this._fieldId); if (values.size > 1) { + if (!Object.prototype.hasOwnProperty.call(data, this._fieldId + "_i18n")) { + data[this._fieldId + "_i18n"] = {}; + } + values.forEach((value, key) => { data[this._fieldId + "_i18n"][key] = value; }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js index b11f778651..7c305e7659 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js @@ -18,6 +18,9 @@ define(["require", "exports", "tslib", "./Field", "../../../Language/Input", ".. const data = {}; const values = LanguageInput.getValues(this._fieldId); if (values.size > 1) { + if (!Object.prototype.hasOwnProperty.call(data, this._fieldId + "_i18n")) { + data[this._fieldId + "_i18n"] = {}; + } values.forEach((value, key) => { data[this._fieldId + "_i18n"][key] = value; }); -- 2.20.1