Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
2dce741f
Commit
2dce741f
authored
Oct 16, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
note about empty values for datepicker and validator
fixes #5580
parent
c68e3ad6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
1 deletion
+16
-1
tutorial-core-validators.md
docs/guide/tutorial-core-validators.md
+8
-1
DatePicker.php
extensions/jui/DatePicker.php
+8
-0
No files found.
docs/guide/tutorial-core-validators.md
View file @
2dce741f
...
@@ -97,7 +97,7 @@ is as specified by the `operator` property.
...
@@ -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
...
@@ -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>
...
...
extensions/jui/DatePicker.php
View file @
2dce741f
...
@@ -38,6 +38,14 @@ use yii\helpers\Json;
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment