mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-07 16:36:42 +08:00
Fix #19322: Revert force setting value to empty string in case it's null in yii\validators\FilterValidator::validateAttribute()
This commit is contained in:
@ -9,6 +9,7 @@ Yii Framework 2 Change Log
|
|||||||
- Bug #19291: Reset errors and validators in `yii\base\Model::__clone()` (WinterSilence)
|
- Bug #19291: Reset errors and validators in `yii\base\Model::__clone()` (WinterSilence)
|
||||||
- Enh #19304: Add filtering validator `yii\validators\TrimValidator` (WinterSilence)
|
- Enh #19304: Add filtering validator `yii\validators\TrimValidator` (WinterSilence)
|
||||||
- Enh #19309: Optimize `yii\base\Model::attributes()` (WinterSilence)
|
- Enh #19309: Optimize `yii\base\Model::attributes()` (WinterSilence)
|
||||||
|
- Bug #19322: Revert force setting value to empty string in case it's `null` in `yii\validators\FilterValidator::validateAttribute()` (bizley)
|
||||||
|
|
||||||
|
|
||||||
2.0.45 February 11, 2022
|
2.0.45 February 11, 2022
|
||||||
|
|||||||
@ -25,6 +25,8 @@ use yii\base\InvalidConfigException;
|
|||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* Many PHP functions qualify this signature (e.g. `trim()`).
|
* Many PHP functions qualify this signature (e.g. `trim()`).
|
||||||
|
* If the callback function requires non-null argument (important since PHP 8.1)
|
||||||
|
* remember to set [[skipOnEmpty]] to `true` otherwise you may trigger an error.
|
||||||
*
|
*
|
||||||
* To specify the filter, set [[filter]] property to be the callback.
|
* To specify the filter, set [[filter]] property to be the callback.
|
||||||
*
|
*
|
||||||
@ -75,7 +77,6 @@ class FilterValidator extends Validator
|
|||||||
{
|
{
|
||||||
$value = $model->$attribute;
|
$value = $model->$attribute;
|
||||||
if (!$this->skipOnArray || !is_array($value)) {
|
if (!$this->skipOnArray || !is_array($value)) {
|
||||||
$value = isset($value) ? $value : '';
|
|
||||||
$model->$attribute = call_user_func($this->filter, $value);
|
$model->$attribute = call_user_func($this->filter, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -526,7 +526,7 @@ class ComplexModel1 extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['id'], 'required', 'except' => 'administration'],
|
[['id'], 'required', 'except' => 'administration'],
|
||||||
[['name', 'description'], 'filter', 'filter' => 'trim'],
|
[['name', 'description'], 'filter', 'filter' => 'trim', 'skipOnEmpty' => true],
|
||||||
[['is_disabled'], 'boolean', 'on' => 'administration'],
|
[['is_disabled'], 'boolean', 'on' => 'administration'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user