Switch map and filter on the array
authorOlaf Braun <info@braun-development.de>
Fri, 2 Aug 2024 15:10:31 +0000 (17:10 +0200)
committerOlaf Braun <info@braun-development.de>
Fri, 2 Aug 2024 15:10:31 +0000 (17:10 +0200)
ts/WoltLabSuite/Core/Form/Builder/Field/Select.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Select.js

index 4222d3eeb9f36b56d1c10fe6327c0115daf66c66..45d69255ac719d7089e02c820091abe4c5e93f61 100644 (file)
@@ -13,14 +13,8 @@ import { FormBuilderData } from "../Data";
 export default class Select extends Field {
   protected _getData(): FormBuilderData {
     const values = Array.from(this._field!.querySelectorAll<HTMLOptionElement>(`option`))
-      .map((input) => {
-        if (input.selected) {
-          return input.value;
-        }
-
-        return null;
-      })
-      .filter((v) => v !== null) as string[];
+      .filter((input) => input.selected)
+      .map((input) => input.value);
 
     return {
       [this._fieldId]: values,
index 1f3dbcf9def2aa8689eec860cdcea06bbf68ab2b..540b34b4e628bb28d19d8483b138c5dad023a8c3 100644 (file)
@@ -13,13 +13,8 @@ define(["require", "exports", "tslib", "./Field"], function (require, exports, t
     class Select extends Field_1.default {
         _getData() {
             const values = Array.from(this._field.querySelectorAll(`option`))
-                .map((input) => {
-                if (input.selected) {
-                    return input.value;
-                }
-                return null;
-            })
-                .filter((v) => v !== null);
+                .filter((input) => input.selected)
+                .map((input) => input.value);
             return {
                 [this._fieldId]: values,
             };