mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
@ -97,7 +97,7 @@ is as specified by the `operator` property.
|
|||||||
|
|
||||||
```php
|
```php
|
||||||
[
|
[
|
||||||
[['from', 'to'], 'date'],
|
[['from_date', 'to_date'], 'date'],
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -113,6 +113,13 @@ specified via [[yii\validators\DateValidator::timestampAttribute|timestampAttrib
|
|||||||
- `timestampAttribute`: the name of the attribute to which this validator may assign the UNIX timestamp
|
- `timestampAttribute`: the name of the attribute to which this validator may assign the UNIX timestamp
|
||||||
converted from the input date/time.
|
converted from the input date/time.
|
||||||
|
|
||||||
|
In case the input is optional you may also want to add a default value filter in addition to the date validator
|
||||||
|
to ensure empty input is stored as `NULL`. Other wise you may end up with dates like `0000-00-00` in your database
|
||||||
|
or `1970-01-01` in the input field of a date picker.
|
||||||
|
|
||||||
|
```php
|
||||||
|
[['from_date', 'to_date'], 'default', 'value' => null],
|
||||||
|
```
|
||||||
|
|
||||||
## [[yii\validators\DefaultValueValidator|default]] <a name="default"></a>
|
## [[yii\validators\DefaultValueValidator|default]] <a name="default"></a>
|
||||||
|
|
||||||
|
@ -38,6 +38,14 @@ use yii\helpers\Json;
|
|||||||
* ]);
|
* ]);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
|
* Note that empty values like empty strings and 0 will result in a date displayed as `1970-01-01`.
|
||||||
|
* So to make sure empty values result in an empty text field in the datepicker you need to add a
|
||||||
|
* validation filter in your model that sets the value to `null` in case when no date has been entered:
|
||||||
|
*
|
||||||
|
* ```php
|
||||||
|
* [['from_date'], 'default', 'value' => null],
|
||||||
|
* ```
|
||||||
|
*
|
||||||
* @see http://api.jqueryui.com/datepicker/
|
* @see http://api.jqueryui.com/datepicker/
|
||||||
* @author Alexander Kochetov <creocoder@gmail.com>
|
* @author Alexander Kochetov <creocoder@gmail.com>
|
||||||
* @author Carsten Brandt <mail@cebe.cc>
|
* @author Carsten Brandt <mail@cebe.cc>
|
||||||
|
Reference in New Issue
Block a user