Commit 266f4f98 by Carsten Brandt

Clientvalidation {value} was not what has been validated

also fixed some inconsistency between client and server validation.
parent 8899aaeb
......@@ -16,6 +16,10 @@ yii.validation = (function ($) {
|| value === '' || trim && $.trim(value) === '';
};
var addMessage = function (messages, message, value) {
messages.push(message.replace(/\{value\}/g, value));
};
return {
required: function (value, messages, options) {
var valid = false;
......@@ -28,7 +32,7 @@ yii.validation = (function ($) {
}
if (!valid) {
messages.push(options.message);
addMessage(messages, options.message, value);
}
},
......@@ -40,7 +44,7 @@ yii.validation = (function ($) {
|| options.strict && (value === options.trueValue || value === options.falseValue);
if (!valid) {
messages.push(options.message);
addMessage(messages, options.message, value);
}
},
......@@ -50,18 +54,18 @@ yii.validation = (function ($) {
}
if (typeof value !== 'string') {
messages.push(options.message);
addMessage(messages, options.message, value);
return;
}
if (options.min !== undefined && value.length < options.min) {
messages.push(options.tooShort);
addMessage(messages, options.tooShort, value);
}
if (options.max !== undefined && value.length > options.max) {
messages.push(options.tooLong);
addMessage(messages, options.tooLong, value);
}
if (options.is !== undefined && value.length != options.is) {
messages.push(options.is);
addMessage(messages, options.is, value);
}
},
......@@ -71,15 +75,15 @@ yii.validation = (function ($) {
}
if (typeof value === 'string' && !value.match(options.pattern)) {
messages.push(options.message);
addMessage(messages, options.message, value);
return;
}
if (options.min !== undefined && value < options.min) {
messages.push(options.tooSmall);
addMessage(messages, options.tooSmall, value);
}
if (options.max !== undefined && value > options.max) {
messages.push(options.tooBig);
addMessage(messages, options.tooBig, value);
}
},
......@@ -91,7 +95,7 @@ yii.validation = (function ($) {
|| options.not && $.inArray(value, options.range) == -1;
if (!valid) {
messages.push(options.message);
addMessage(messages, options.message, value);
}
},
......@@ -101,7 +105,7 @@ yii.validation = (function ($) {
}
if (!options.not && !value.match(options.pattern) || options.not && value.match(options.pattern)) {
messages.push(options.message)
addMessage(messages, options.message, value);
}
},
......@@ -123,7 +127,7 @@ yii.validation = (function ($) {
}
if (!valid || !(value.match(options.pattern) && (!options.allowName || value.match(options.fullPattern)))) {
messages.push(options.message);
addMessage(messages, options.message, value);
}
},
......@@ -149,7 +153,7 @@ yii.validation = (function ($) {
}
if (!valid || !value.match(options.pattern)) {
messages.push(options.message);
addMessage(messages, options.message, value);
}
},
......@@ -170,7 +174,7 @@ yii.validation = (function ($) {
h += v.charCodeAt(i);
}
if (h != hash) {
messages.push(options.message);
addMessage(messages, options.message, value);
}
},
......@@ -210,10 +214,13 @@ yii.validation = (function ($) {
case '<=':
valid = value <= compareValue;
break;
default:
valid = false;
break;
}
if (!valid) {
messages.push(options.message);
addMessage(messages, options.message, value);
}
}
};
......
......@@ -90,7 +90,6 @@ class BooleanValidator extends Validator
'falseValue' => $this->falseValue,
'message' => Html::encode(strtr($this->message, array(
'{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute,
'{true}' => $this->trueValue,
'{false}' => $this->falseValue,
))),
......
......@@ -170,6 +170,7 @@ class CompareValidator extends Validator
case '>=': return $value >= $this->compareValue;
case '<': return $value < $this->compareValue;
case '<=': return $value <= $this->compareValue;
default: return false;
}
}
......@@ -201,7 +202,7 @@ class CompareValidator extends Validator
$options['message'] = Html::encode(strtr($this->message, array(
'{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute,
'{compareAttribute}' => $compareValue,
'{compareValue}' => $compareValue,
)));
......
......@@ -131,7 +131,6 @@ class EmailValidator extends Validator
'allowName' => $this->allowName,
'message' => Html::encode(strtr($this->message, array(
'{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute,
))),
'enableIDN' => (boolean)$this->enableIDN,
);
......
......@@ -121,13 +121,11 @@ class NumberValidator extends Validator
public function clientValidateAttribute($object, $attribute, $view)
{
$label = $object->getAttributeLabel($attribute);
$value = $object->$attribute;
$options = array(
'pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern),
'message' => Html::encode(strtr($this->message, array(
'{attribute}' => $label,
'{value}' => $value,
))),
);
......@@ -135,7 +133,6 @@ class NumberValidator extends Validator
$options['min'] = $this->min;
$options['tooSmall'] = Html::encode(strtr($this->tooSmall, array(
'{attribute}' => $label,
'{value}' => $value,
'{min}' => $this->min,
)));
}
......@@ -143,7 +140,6 @@ class NumberValidator extends Validator
$options['max'] = $this->max;
$options['tooBig'] = Html::encode(strtr($this->tooBig, array(
'{attribute}' => $label,
'{value}' => $value,
'{max}' => $this->max,
)));
}
......
......@@ -96,7 +96,6 @@ class RangeValidator extends Validator
'not' => $this->not,
'message' => Html::encode(strtr($this->message, array(
'{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute,
))),
);
if ($this->skipOnEmpty) {
......
......@@ -103,7 +103,6 @@ class RegularExpressionValidator extends Validator
'not' => $this->not,
'message' => Html::encode(strtr($this->message, array(
'{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute,
))),
);
if ($this->skipOnEmpty) {
......
......@@ -123,7 +123,6 @@ class RequiredValidator extends Validator
$options['message'] = Html::encode(strtr($options['message'], array(
'{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute,
)));
ValidationAsset::register($view);
......
......@@ -149,12 +149,10 @@ class StringValidator extends Validator
public function clientValidateAttribute($object, $attribute, $view)
{
$label = $object->getAttributeLabel($attribute);
$value = $object->$attribute;
$options = array(
'message' => Html::encode(strtr($this->message, array(
'{attribute}' => $label,
'{value}' => $value,
))),
);
......@@ -162,7 +160,6 @@ class StringValidator extends Validator
$options['min'] = $this->min;
$options['tooShort'] = Html::encode(strtr($this->tooShort, array(
'{attribute}' => $label,
'{value}' => $value,
'{min}' => $this->min,
)));
}
......@@ -170,7 +167,6 @@ class StringValidator extends Validator
$options['max'] = $this->max;
$options['tooLong'] = Html::encode(strtr($this->tooLong, array(
'{attribute}' => $label,
'{value}' => $value,
'{max}' => $this->max,
)));
}
......@@ -178,7 +174,6 @@ class StringValidator extends Validator
$options['is'] = $this->length;
$options['notEqual'] = Html::encode(strtr($this->notEqual, array(
'{attribute}' => $label,
'{value}' => $value,
'{length}' => $this->is,
)));
}
......
......@@ -132,7 +132,6 @@ class UrlValidator extends Validator
'pattern' => new JsExpression($pattern),
'message' => Html::encode(strtr($this->message, array(
'{attribute}' => $object->getAttributeLabel($attribute),
'{value}' => $object->$attribute,
))),
'enableIDN' => (boolean)$this->enableIDN,
);
......
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