From: Matthias Schmidt Date: Wed, 9 Oct 2019 17:04:02 +0000 (+0200) Subject: Fix conditions for multi-value fields X-Git-Tag: 5.2.0_Beta_3~40 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=536c2ec4cba0c5c3de6f06ccae1460c9cc63883f;p=GitHub%2FWoltLab%2FWCF.git Fix conditions for multi-value fields --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract.js index 180f9c6864..62bb5e363e 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Abstract.js @@ -76,7 +76,13 @@ define(['./Manager'], function(DependencyManager) { }.bind(this)); if (!this._fields.length) { - throw new Error("Unknown field with id '" + fieldId + "'."); + elBySelAll('input[type=checkbox][name="' + fieldId + '[]"]', undefined, function(field) { + this._fields.push(field); + }.bind(this)); + + if (!this._fields.length) { + throw new Error("Unknown field with id '" + fieldId + "'."); + } } } else { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Value.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Value.js index d39b880d49..68f49d6d33 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Value.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Value.js @@ -28,13 +28,13 @@ define(['./Abstract', 'Core', './Manager'], function(Abstract, Core, Manager) { throw new Error("Values have not been set."); } - var value; + var values = []; if (this._field) { if (Manager.isHiddenByDependencies(this._field)) { return false; } - value = this._field.value; + values.push(this._field.value); } else { for (var i = 0, length = this._fields.length, field; i < length; i++) { @@ -45,21 +45,21 @@ define(['./Abstract', 'Core', './Manager'], function(Abstract, Core, Manager) { return false; } - value = field.value; - - break; + values.push(field.value); } } } // do not use `Array.prototype.indexOf()` as we use a weak comparision for (var i = 0, length = this._values.length; i < length; i++) { - if (this._values[i] == value) { - if (this._isNegated) { - return false; + for (var j = 0, length2 = values.length; j < length2; j++) { + if (this._values[i] == values[j]) { + if (this._isNegated) { + return false; + } + + return true; } - - return true; } } diff --git a/wcfsetup/install/files/lib/system/form/builder/field/dependency/ValueFormFieldDependency.class.php b/wcfsetup/install/files/lib/system/form/builder/field/dependency/ValueFormFieldDependency.class.php index 9e11172d1e..57edd6d7b6 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/dependency/ValueFormFieldDependency.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/dependency/ValueFormFieldDependency.class.php @@ -34,13 +34,27 @@ class ValueFormFieldDependency extends AbstractFormFieldDependency { * @inheritDoc */ public function checkDependency() { - $inArray = in_array($this->getField()->getValue(), $this->getValues()); + if (is_array($this->getField()->getValue())) { + $check = false; + // do not use `array_diff` because we use weak comparison + foreach ($this->getValues() as $possibleValue) { + foreach ($this->getField()->getValue() as $actualValue) { + if ($possibleValue == $actualValue) { + $check = true; + break; + } + } + } + } + else { + $check = in_array($this->getField()->getValue(), $this->getValues()); + } if ($this->isNegated()) { - return !$inArray; + return !$check; } - return $inArray; + return $check; } /**