This commit is contained in:
zxcq544
2014-06-12 18:35:45 +04:00

View File

@@ -342,11 +342,11 @@ by calling `validateValue()`.
### Handling Empty Inputs <a name="handling-empty-inputs"></a> ### Handling Empty Inputs <a name="handling-empty-inputs"></a>
Validators often need to check if an input is empty or not. You may call [[yii\validators\Validator::isEmpty()]] Validators often need to check if an input is empty or not. In your validator, you may call [[yii\validators\Validator::isEmpty()]]
to perform this check. By default, this method will return true if a value is an empty string, an empty array or null. to perform this check. By default, this method will return true if a value is an empty string, an empty array or null.
Users of validators can customize the default empty detection logic by configuring Users of validators can customize the default empty detection logic by configuring
the [[yii\validators\Validator::isEmpty]] property. For example, the [[yii\validators\Validator::isEmpty]] property with a PHP callable. For example,
```php ```php
[ [
@@ -356,6 +356,16 @@ the [[yii\validators\Validator::isEmpty]] property. For example,
] ]
``` ```
When input data are submitted from HTML forms, you often need to assign some default values to the inputs
if they are empty. You can do so by using the [default](tutorial-core-validators.md#default) validator. For example,
```php
[
// set "level" to be 1 if it is empty
['level', 'default', 'value' => 1],
]
```
## Client-Side Validation <a name="client-side-validation"></a> ## Client-Side Validation <a name="client-side-validation"></a>