From: MysteryCode Date: Mon, 14 Jun 2021 05:23:27 +0000 (+0200) Subject: Fix reading i18n data from form builder forms (#4284) X-Git-Tag: 5.4.0_Beta_2~21 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=bff3d7ab50fbc25d5a99feb94fd0f04ed8b004d6;p=GitHub%2FWoltLab%2FWCF.git 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). --- 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; });