mirror of
https://github.com/yiisoft/yii2.git
synced 2026-03-08 08:17:24 +01:00
Fixes #7566: Improved \yii\validators\CompareValidator default messages
This commit is contained in:
committed by
Alexander Makarov
parent
bb2bc7008d
commit
c33574bc0a
@@ -87,28 +87,28 @@ class CompareValidator extends Validator
|
||||
if ($this->message === null) {
|
||||
switch ($this->operator) {
|
||||
case '==':
|
||||
$this->message = Yii::t('yii', '{attribute} must be repeated exactly.');
|
||||
$this->message = Yii::t('yii', '{attribute} must be equal to "{compareValueOrAttribute}".');
|
||||
break;
|
||||
case '===':
|
||||
$this->message = Yii::t('yii', '{attribute} must be repeated exactly.');
|
||||
$this->message = Yii::t('yii', '{attribute} must be equal to "{compareValueOrAttribute}".');
|
||||
break;
|
||||
case '!=':
|
||||
$this->message = Yii::t('yii', '{attribute} must not be equal to "{compareValue}".');
|
||||
$this->message = Yii::t('yii', '{attribute} must not be equal to "{compareValueOrAttribute}".');
|
||||
break;
|
||||
case '!==':
|
||||
$this->message = Yii::t('yii', '{attribute} must not be equal to "{compareValue}".');
|
||||
$this->message = Yii::t('yii', '{attribute} must not be equal to "{compareValueOrAttribute}".');
|
||||
break;
|
||||
case '>':
|
||||
$this->message = Yii::t('yii', '{attribute} must be greater than "{compareValue}".');
|
||||
$this->message = Yii::t('yii', '{attribute} must be greater than "{compareValueOrAttribute}".');
|
||||
break;
|
||||
case '>=':
|
||||
$this->message = Yii::t('yii', '{attribute} must be greater than or equal to "{compareValue}".');
|
||||
$this->message = Yii::t('yii', '{attribute} must be greater than or equal to "{compareValueOrAttribute}".');
|
||||
break;
|
||||
case '<':
|
||||
$this->message = Yii::t('yii', '{attribute} must be less than "{compareValue}".');
|
||||
$this->message = Yii::t('yii', '{attribute} must be less than "{compareValueOrAttribute}".');
|
||||
break;
|
||||
case '<=':
|
||||
$this->message = Yii::t('yii', '{attribute} must be less than or equal to "{compareValue}".');
|
||||
$this->message = Yii::t('yii', '{attribute} must be less than or equal to "{compareValueOrAttribute}".');
|
||||
break;
|
||||
default:
|
||||
throw new InvalidConfigException("Unknown operator: {$this->operator}");
|
||||
@@ -128,17 +128,18 @@ class CompareValidator extends Validator
|
||||
return;
|
||||
}
|
||||
if ($this->compareValue !== null) {
|
||||
$compareLabel = $compareValue = $this->compareValue;
|
||||
$compareLabel = $compareValue = $compareValueOrAttribute = $this->compareValue;
|
||||
} else {
|
||||
$compareAttribute = $this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute;
|
||||
$compareValue = $model->$compareAttribute;
|
||||
$compareLabel = $model->getAttributeLabel($compareAttribute);
|
||||
$compareLabel = $compareValueOrAttribute = $model->getAttributeLabel($compareAttribute);
|
||||
}
|
||||
|
||||
if (!$this->compareValues($this->operator, $this->type, $value, $compareValue)) {
|
||||
$this->addError($model, $attribute, $this->message, [
|
||||
'compareAttribute' => $compareLabel,
|
||||
'compareValue' => $compareValue,
|
||||
'compareValueOrAttribute' => $compareValueOrAttribute,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user