Commit 4239b2a5 by Alexander Makarov

Fixes #1870: Validation errors weren't properly translated when using clientside validation

parent 718ddfb9
......@@ -24,6 +24,7 @@ Yii Framework 2 Change Log
- Bug #1798: Fixed label attributes for array fields (zhuravljov)
- Bug #1800: Better check for `$_SERVER['HTTPS']` in `yii\web\Request::getIsSecureConnection()` (ginus, samdark)
- Bug #1827: Debugger toolbar is loaded twice if an action is calling `run()` to execute another action (qiangxue)
- Bug #1870: Validation errors weren't properly translated when using clientside validation (samdark)
- Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark)
- Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark)
- Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
......
......@@ -72,10 +72,10 @@ class BooleanValidator extends Validator
$options = [
'trueValue' => $this->trueValue,
'falseValue' => $this->falseValue,
'message' => strtr($this->message, [
'{attribute}' => $object->getAttributeLabel($attribute),
'{true}' => $this->trueValue,
'{false}' => $this->falseValue,
'message' => Yii::t('yii', $this->message, [
'attribute' => $object->getAttributeLabel($attribute),
'true' => $this->trueValue,
'false' => $this->falseValue,
]),
];
if ($this->skipOnEmpty) {
......
......@@ -195,10 +195,10 @@ class CompareValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$options['message'] = strtr($this->message, [
'{attribute}' => $object->getAttributeLabel($attribute),
'{compareAttribute}' => $compareValue,
'{compareValue}' => $compareValue,
$options['message'] = Yii::t('yii', $this->message, [
'attribute' => $object->getAttributeLabel($attribute),
'compareAttribute' => $compareValue,
'compareValue' => $compareValue,
]);
ValidationAsset::register($view);
......
......@@ -98,8 +98,8 @@ class EmailValidator extends Validator
'pattern' => new JsExpression($this->pattern),
'fullPattern' => new JsExpression($this->fullPattern),
'allowName' => $this->allowName,
'message' => strtr($this->message, [
'{attribute}' => $object->getAttributeLabel($attribute),
'message' => Yii::t('yii', $this->message, [
'attribute' => $object->getAttributeLabel($attribute),
]),
'enableIDN' => (boolean)$this->enableIDN,
];
......
......@@ -124,23 +124,23 @@ class NumberValidator extends Validator
$options = [
'pattern' => new JsExpression($this->integerOnly ? $this->integerPattern : $this->numberPattern),
'message' => strtr($this->message, [
'{attribute}' => $label,
'message' => Yii::t('yii', $this->message, [
'attribute' => $label,
]),
];
if ($this->min !== null) {
$options['min'] = $this->min;
$options['tooSmall'] = strtr($this->tooSmall, [
'{attribute}' => $label,
'{min}' => $this->min,
$options['tooSmall'] = Yii::t('yii', $this->tooSmall, [
'attribute' => $label,
'min' => $this->min,
]);
}
if ($this->max !== null) {
$options['max'] = $this->max;
$options['tooBig'] = strtr($this->tooBig, [
'{attribute}' => $label,
'{max}' => $this->max,
$options['tooBig'] = Yii::t('yii', $this->tooBig, [
'attribute' => $label,
'max' => $this->max,
]);
}
if ($this->skipOnEmpty) {
......
......@@ -73,8 +73,8 @@ class RangeValidator extends Validator
$options = [
'range' => $range,
'not' => $this->not,
'message' => strtr($this->message, [
'{attribute}' => $object->getAttributeLabel($attribute),
'message' => Yii::t('yii', $this->message, [
'attribute' => $object->getAttributeLabel($attribute),
]),
];
if ($this->skipOnEmpty) {
......
......@@ -80,8 +80,8 @@ class RegularExpressionValidator extends Validator
$options = [
'pattern' => new JsExpression($pattern),
'not' => $this->not,
'message' => strtr($this->message, [
'{attribute}' => $object->getAttributeLabel($attribute),
'message' => Yii::t('yii', $this->message, [
'attribute' => $object->getAttributeLabel($attribute),
]),
];
if ($this->skipOnEmpty) {
......
......@@ -90,8 +90,8 @@ class RequiredValidator extends Validator
{
$options = [];
if ($this->requiredValue !== null) {
$options['message'] = strtr($this->message, [
'{requiredValue}' => $this->requiredValue,
$options['message'] = Yii::t('yii', $this->message, [
'requiredValue' => $this->requiredValue,
]);
$options['requiredValue'] = $this->requiredValue;
} else {
......@@ -101,8 +101,8 @@ class RequiredValidator extends Validator
$options['strict'] = 1;
}
$options['message'] = strtr($options['message'], [
'{attribute}' => $object->getAttributeLabel($attribute),
$options['message'] = Yii::t('yii', $options['message'], [
'attribute' => $object->getAttributeLabel($attribute),
]);
ValidationAsset::register($view);
......
......@@ -151,30 +151,30 @@ class StringValidator extends Validator
$label = $object->getAttributeLabel($attribute);
$options = [
'message' => strtr($this->message, [
'message' => Yii::t('yii', $this->message, [
'{attribute}' => $label,
]),
];
if ($this->min !== null) {
$options['min'] = $this->min;
$options['tooShort'] = strtr($this->tooShort, [
'{attribute}' => $label,
'{min}' => $this->min,
$options['tooShort'] = Yii::t('yii', $this->tooShort, [
'attribute' => $label,
'min' => $this->min,
]);
}
if ($this->max !== null) {
$options['max'] = $this->max;
$options['tooLong'] = strtr($this->tooLong, [
'{attribute}' => $label,
'{max}' => $this->max,
$options['tooLong'] = Yii::t('yii', $this->tooLong, [
'attribute' => $label,
'max' => $this->max,
]);
}
if ($this->length !== null) {
$options['is'] = $this->length;
$options['notEqual'] = strtr($this->notEqual, [
'{attribute}' => $label,
'{length}' => $this->length,
$options['notEqual'] = Yii::t('yii', $this->notEqual, [
'attribute' => $label,
'length' => $this->length,
]);
}
if ($this->skipOnEmpty) {
......
......@@ -121,8 +121,8 @@ class UrlValidator extends Validator
$options = [
'pattern' => new JsExpression($pattern),
'message' => strtr($this->message, [
'{attribute}' => $object->getAttributeLabel($attribute),
'message' => Yii::t('yii', $this->message, [
'attribute' => $object->getAttributeLabel($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