diff --git a/framework/yii/assets/yii.validation.js b/framework/yii/assets/yii.validation.js index 015040e..3ce9edb 100644 --- a/framework/yii/assets/yii.validation.js +++ b/framework/yii/assets/yii.validation.js @@ -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); } } }; diff --git a/framework/yii/validators/BooleanValidator.php b/framework/yii/validators/BooleanValidator.php index d1e81b8..7eb1427 100644 --- a/framework/yii/validators/BooleanValidator.php +++ b/framework/yii/validators/BooleanValidator.php @@ -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, ))), diff --git a/framework/yii/validators/CompareValidator.php b/framework/yii/validators/CompareValidator.php index 8c9e587..35e044a 100644 --- a/framework/yii/validators/CompareValidator.php +++ b/framework/yii/validators/CompareValidator.php @@ -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, ))); diff --git a/framework/yii/validators/EmailValidator.php b/framework/yii/validators/EmailValidator.php index c3d8480..7081cfb 100644 --- a/framework/yii/validators/EmailValidator.php +++ b/framework/yii/validators/EmailValidator.php @@ -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, ); diff --git a/framework/yii/validators/NumberValidator.php b/framework/yii/validators/NumberValidator.php index 2fee133..960828d 100644 --- a/framework/yii/validators/NumberValidator.php +++ b/framework/yii/validators/NumberValidator.php @@ -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, ))); } diff --git a/framework/yii/validators/RangeValidator.php b/framework/yii/validators/RangeValidator.php index f89d420..fedc027 100644 --- a/framework/yii/validators/RangeValidator.php +++ b/framework/yii/validators/RangeValidator.php @@ -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) { diff --git a/framework/yii/validators/RegularExpressionValidator.php b/framework/yii/validators/RegularExpressionValidator.php index df57e7d..f5c5d02 100644 --- a/framework/yii/validators/RegularExpressionValidator.php +++ b/framework/yii/validators/RegularExpressionValidator.php @@ -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) { diff --git a/framework/yii/validators/RequiredValidator.php b/framework/yii/validators/RequiredValidator.php index 9ca0ecb..68968be 100644 --- a/framework/yii/validators/RequiredValidator.php +++ b/framework/yii/validators/RequiredValidator.php @@ -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); diff --git a/framework/yii/validators/StringValidator.php b/framework/yii/validators/StringValidator.php index 946ca6e..166d2d6 100644 --- a/framework/yii/validators/StringValidator.php +++ b/framework/yii/validators/StringValidator.php @@ -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, ))); } diff --git a/framework/yii/validators/UrlValidator.php b/framework/yii/validators/UrlValidator.php index aa3dad1..9230b36 100644 --- a/framework/yii/validators/UrlValidator.php +++ b/framework/yii/validators/UrlValidator.php @@ -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, );