Commit cd898c1b by Qiang Xue

Merge pull request #3558 from creocoder/range-validator-js-enh

[WIP] Additional RangeValidator fixes
parents e1b47770 12a143bd
......@@ -91,10 +91,24 @@ yii.validation = (function ($) {
if (options.skipOnEmpty && pub.isEmpty(value)) {
return;
}
var valid = !options.not && $.inArray(value, options.range) > -1
|| options.not && $.inArray(value, options.range) == -1;
if (!valid) {
if (!options.allowArray && $.isArray(value)) {
pub.addMessage(messages, options.message, value);
return;
}
var inArray = true;
$.each($.isArray(value) ? value : [value], function(i, v) {
if ($.inArray(v, options.range) == -1) {
inArray = false;
return false;
} else {
return true;
}
});
if (options.not !== inArray) {
pub.addMessage(messages, options.message, value);
}
},
......
......@@ -72,7 +72,7 @@ class RangeValidator extends Validator
}
}
return ($this->not xor $in) ? null : [$this->message, []];
return $this->not !== $in ? null : [$this->message, []];
}
/**
......@@ -94,6 +94,9 @@ class RangeValidator extends Validator
if ($this->skipOnEmpty) {
$options['skipOnEmpty'] = 1;
}
if ($this->allowArray) {
$options['allowArray'] = 1;
}
ValidationAsset::register($view);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment