}.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 {
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++) {
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;
}
}
* @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;
}
/**