Fix the initialization of the checkboxes form builder component
authorAlexander Ebert <ebert@woltlab.com>
Fri, 18 Aug 2023 11:43:40 +0000 (13:43 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 18 Aug 2023 11:43:40 +0000 (13:43 +0200)
Fixes #5620

This is the same kind of problem that was previously fixed in a4e3ea3117209c624ae2f3bb9be4d04c5234cb5d

ts/WoltLabSuite/Core/Form/Builder/Field/Checkboxes.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Checkboxes.js

index 8b134d94c00d5152e2e0ec5339318af7eac9092e..417ff880cf683f524e36f259bcb84d102464faa3 100644 (file)
@@ -14,6 +14,12 @@ import { escapeAttributeSelector } from "WoltLabSuite/Core/Dom/Util";
 class Checkboxes extends Field {
   protected _fields: HTMLInputElement[];
 
+  constructor(fieldId: string) {
+    super(fieldId);
+
+    this._fields = Array.from(document.querySelectorAll(`input[name="${escapeAttributeSelector(this._fieldId)}[]"]`));
+  }
+
   protected _getData(): FormBuilderData {
     const values = this._fields
       .map((input) => {
@@ -31,7 +37,7 @@ class Checkboxes extends Field {
   }
 
   protected _readField(): void {
-    this._fields = Array.from(document.querySelectorAll(`input[name="${escapeAttributeSelector(this._fieldId)}[]"]`));
+    /* Does nothing. */
   }
 }
 
index 4224f2ff077d7d4442cf8a2898429a8b3b379018..971818c44f41d4c40ddd976cc9827939f4ea6729 100644 (file)
@@ -11,6 +11,10 @@ define(["require", "exports", "tslib", "./Field", "WoltLabSuite/Core/Dom/Util"],
     Field_1 = tslib_1.__importDefault(Field_1);
     class Checkboxes extends Field_1.default {
         _fields;
+        constructor(fieldId) {
+            super(fieldId);
+            this._fields = Array.from(document.querySelectorAll(`input[name="${(0, Util_1.escapeAttributeSelector)(this._fieldId)}[]"]`));
+        }
         _getData() {
             const values = this._fields
                 .map((input) => {
@@ -25,7 +29,7 @@ define(["require", "exports", "tslib", "./Field", "WoltLabSuite/Core/Dom/Util"],
             };
         }
         _readField() {
-            this._fields = Array.from(document.querySelectorAll(`input[name="${(0, Util_1.escapeAttributeSelector)(this._fieldId)}[]"]`));
+            /* Does nothing. */
         }
     }
     return Checkboxes;