Fix reading i18n data from form builder forms (#4284)
authorMysteryCode <mutec@users.noreply.github.com>
Mon, 14 Jun 2021 05:23:27 +0000 (07:23 +0200)
committerGitHub <noreply@github.com>
Mon, 14 Jun 2021 05:23:27 +0000 (07:23 +0200)
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
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/ValueI18n.js

index 8cafa4b2ea7184b247e0b0d50f4216f74d10f2a1..20b083f045dd606aa4ed4c22ca0714d86bdef63e 100644 (file)
@@ -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;
       });
index b11f77865181f96888eb02ed22c4161989e45f1e..7c305e76592723fc826daa463de073e27e2b5e64 100644 (file)
@@ -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;
                 });