From 12de1ff429d7e1fdc34d236b8e521fe2cd2491bb Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 3 Jul 2019 18:19:02 +0200 Subject: [PATCH] Resolve TODOs in form builder dependency JS code See #2509 --- .../Core/Form/Builder/Field/Dependency/Empty.js | 9 +++++---- .../Core/Form/Builder/Field/Dependency/NonEmpty.js | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js index d14b1ca29b..30e79c8c1d 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Empty.js @@ -26,7 +26,6 @@ define(['./Abstract', 'Core'], function(Abstract, Core) { case 'INPUT': switch (this._field.type) { case 'checkbox': - // TODO: check if working return !this._field.checked; case 'radio': @@ -41,11 +40,13 @@ define(['./Abstract', 'Core'], function(Abstract, Core) { } case 'SELECT': - // TODO: check if working for multiselect - return this._field.value.length === 0; + if (this._field.multiple) { + return elBySelAll('option:checked', this._field).length === 0; + } + + return this._field.value == 0 || this._field.value.length === 0; case 'TEXTAREA': - // TODO: check if working return this._field.value.trim().length === 0; } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/NonEmpty.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/NonEmpty.js index 983e39570d..b84d8def58 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/NonEmpty.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/NonEmpty.js @@ -26,7 +26,6 @@ define(['./Abstract', 'Core'], function(Abstract, Core) { case 'INPUT': switch (this._field.type) { case 'checkbox': - // TODO: check if working return this._field.checked; case 'radio': @@ -41,11 +40,13 @@ define(['./Abstract', 'Core'], function(Abstract, Core) { } case 'SELECT': - // TODO: check if working for multiselect - return this._field.value.length !== 0; + if (this._field.multiple) { + return elBySelAll('option:checked', this._field).length !== 0; + } + + return this._field.value != 0 && this._field.value.length !== 0; case 'TEXTAREA': - // TODO: check if working return this._field.value.trim().length !== 0; } } -- 2.20.1