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
d1363d96
Commit
d1363d96
authored
Mar 22, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Validator::whenClient.
parent
bbc7b076
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
13 deletions
+38
-13
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Validator.php
framework/validators/Validator.php
+37
-13
No files found.
framework/CHANGELOG.md
View file @
d1363d96
...
@@ -135,6 +135,7 @@ Yii Framework 2 Change Log
...
@@ -135,6 +135,7 @@ Yii Framework 2 Change Log
-
Enh #2364: Take into account current error reporting level in error handler (gureedo)
-
Enh #2364: Take into account current error reporting level in error handler (gureedo)
-
Enh #2387: Added support for fetching data from database in batches (nineinchnick, qiangxue)
-
Enh #2387: Added support for fetching data from database in batches (nineinchnick, qiangxue)
-
Enh #2392: Added
`addCssStyle()`
,
`removeCssStyle()`
,
`cssStyleFromArray()`
and
`cssStyleToArray()`
to
`Html`
(qiangxue, kartik-v, Alex-Code)
-
Enh #2392: Added
`addCssStyle()`
,
`removeCssStyle()`
,
`cssStyleFromArray()`
and
`cssStyleToArray()`
to
`Html`
(qiangxue, kartik-v, Alex-Code)
-
Enh #2406: Added support for conditional validation (drenty, cebe, qiangxue)
-
Enh #2411: Added Gii extension generator (schmunk42)
-
Enh #2411: Added Gii extension generator (schmunk42)
-
Enh #2415: Added support for inverse relations (qiangxue)
-
Enh #2415: Added support for inverse relations (qiangxue)
-
Enh #2417: Added possibility to set
`dataType`
for
`$.ajax`
call in yii.activeForm.js (Borales)
-
Enh #2417: Added possibility to set
`dataType`
for
`$.ajax`
call in yii.activeForm.js (Borales)
...
...
framework/validators/Validator.php
View file @
d1363d96
...
@@ -128,12 +128,44 @@ class Validator extends Component
...
@@ -128,12 +128,44 @@ class Validator extends Component
*/
*/
public
$isEmpty
;
public
$isEmpty
;
/**
/**
* @var callable a PHP callable that determines the conditions upon which the validation is performed.
* @var callable a PHP callable whose return value determines whether this validator should be applied.
* If not set, the validation will always be performed. If set, the client-side validation is disabled.
* The signature of the callable should be `function ($model, $attribute)`, where `$model` and `$attribute`
* The signature of the callable should be `function ($model)` which takes the model to be validated as a
* refer to the model and the attribute currently being validated. The callable should return a boolean value.
* parameter and returns a boolean indicating whether the validation should be performed.
*
* This property is mainly provided to support conditional validation on the server side.
* If this property is not set, this validator will be always applied on the server side.
*
* The following example will enable the validator only when the country currently selected is USA:
*
* ```php
* function ($model) {
* return $model->country == Country::USA;
* }
* ```
*
* @see whenClient
*/
*/
public
$when
;
public
$when
;
/**
* @var string a JavaScript function name whose return value determines whether this validator should be applied
* on the client side. The signature of the function should be `function (attribute, value)`, where
* `attribute` is the name of the attribute being validated and `value` the current value of the attribute.
*
* This property is mainly provided to support conditional validation on the client side.
* If this property is not set, this validator will be always applied on the client side.
*
* The following example will enable the validator only when the country currently selected is USA:
*
* ```php
* function (attribute, value) {
* return $('#country').value == 'USA';
* }
* ```
*
* @see when
*/
public
$whenClient
;
/**
/**
* Creates a validator object.
* Creates a validator object.
...
@@ -178,10 +210,6 @@ class Validator extends Component
...
@@ -178,10 +210,6 @@ class Validator extends Component
$this
->
attributes
=
(
array
)
$this
->
attributes
;
$this
->
attributes
=
(
array
)
$this
->
attributes
;
$this
->
on
=
(
array
)
$this
->
on
;
$this
->
on
=
(
array
)
$this
->
on
;
$this
->
except
=
(
array
)
$this
->
except
;
$this
->
except
=
(
array
)
$this
->
except
;
if
(
$this
->
when
!==
null
)
{
$this
->
enableClientValidation
=
false
;
}
}
}
/**
/**
...
@@ -203,11 +231,7 @@ class Validator extends Component
...
@@ -203,11 +231,7 @@ class Validator extends Component
$skip
=
$this
->
skipOnError
&&
$object
->
hasErrors
(
$attribute
)
$skip
=
$this
->
skipOnError
&&
$object
->
hasErrors
(
$attribute
)
||
$this
->
skipOnEmpty
&&
$this
->
isEmpty
(
$object
->
$attribute
);
||
$this
->
skipOnEmpty
&&
$this
->
isEmpty
(
$object
->
$attribute
);
if
(
!
$skip
)
{
if
(
!
$skip
)
{
if
(
$this
->
when
!==
null
)
{
if
(
$this
->
when
===
null
||
call_user_func
(
$this
->
when
,
$object
,
$attribute
))
{
if
(
call_user_func
(
$this
->
when
,
$object
))
{
$this
->
validateAttribute
(
$object
,
$attribute
);
}
}
else
{
$this
->
validateAttribute
(
$object
,
$attribute
);
$this
->
validateAttribute
(
$object
,
$attribute
);
}
}
}
}
...
...
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