mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
This commit is contained in:

committed by
Paul Klimov

parent
e96f956f8a
commit
1ed6fc09f6
@ -129,7 +129,9 @@ class EachValidator extends Validator
|
||||
$filteredValue = [];
|
||||
foreach ($value as $k => $v) {
|
||||
$model->$attribute = $v;
|
||||
$validator->validateAttribute($model, $attribute);
|
||||
if (!$validator->skipOnEmpty || !$validator->isEmpty($v)) {
|
||||
$validator->validateAttribute($model, $attribute);
|
||||
}
|
||||
$filteredValue[$k] = $model->$attribute;
|
||||
if ($model->hasErrors($attribute)) {
|
||||
$validationErrors = $model->getErrors($attribute);
|
||||
|
@ -107,6 +107,20 @@ class EachValidatorTest extends TestCase
|
||||
|
||||
$validator = new EachValidator(['rule' => ['integer', 'skipOnEmpty' => false]]);
|
||||
$this->assertFalse($validator->validate(['']));
|
||||
|
||||
$model = FakedValidationModel::createWithAttributes([
|
||||
'attr_one' => [
|
||||
''
|
||||
],
|
||||
]);
|
||||
$validator = new EachValidator(['rule' => ['integer', 'skipOnEmpty' => true]]);
|
||||
$validator->validateAttribute($model, 'attr_one');
|
||||
$this->assertFalse($model->hasErrors('attr_one'));
|
||||
|
||||
$model->clearErrors();
|
||||
$validator = new EachValidator(['rule' => ['integer', 'skipOnEmpty' => false]]);
|
||||
$validator->validateAttribute($model, 'attr_one');
|
||||
$this->assertTrue($model->hasErrors('attr_one'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user