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
f7b8595f
Commit
f7b8595f
authored
May 15, 2013
by
resurtm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validator::clientValidateAttribute() now accepts third parameter: a view.
punycode.js asset bundle registering moved from ActiveField to validators.
parent
6458b8df
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
45 additions
and
22 deletions
+45
-22
BooleanValidator.php
yii/validators/BooleanValidator.php
+3
-1
CaptchaValidator.php
yii/validators/CaptchaValidator.php
+3
-1
CompareValidator.php
yii/validators/CompareValidator.php
+3
-1
EmailValidator.php
yii/validators/EmailValidator.php
+7
-1
InlineValidator.php
yii/validators/InlineValidator.php
+3
-1
NumberValidator.php
yii/validators/NumberValidator.php
+3
-1
RangeValidator.php
yii/validators/RangeValidator.php
+3
-1
RegularExpressionValidator.php
yii/validators/RegularExpressionValidator.php
+3
-1
RequiredValidator.php
yii/validators/RequiredValidator.php
+3
-1
StringValidator.php
yii/validators/StringValidator.php
+3
-1
UrlValidator.php
yii/validators/UrlValidator.php
+7
-1
Validator.php
yii/validators/Validator.php
+3
-1
ActiveField.php
yii/widgets/ActiveField.php
+1
-10
No files found.
yii/validators/BooleanValidator.php
View file @
f7b8595f
...
...
@@ -79,9 +79,11 @@ class BooleanValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$options
=
array
(
'trueValue'
=>
$this
->
trueValue
,
...
...
yii/validators/CaptchaValidator.php
View file @
f7b8595f
...
...
@@ -91,9 +91,11 @@ class CaptchaValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$captcha
=
$this
->
getCaptchaAction
();
$code
=
$captcha
->
getVerifyCode
(
false
);
...
...
yii/validators/CompareValidator.php
View file @
f7b8595f
...
...
@@ -178,9 +178,11 @@ class CompareValidator extends Validator
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated
* @return string the client-side validation script
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @throws InvalidConfigException if CompareValidator::operator is invalid
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$options
=
array
(
'operator'
=>
$this
->
operator
);
...
...
yii/validators/EmailValidator.php
View file @
f7b8595f
...
...
@@ -113,10 +113,16 @@ class EmailValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
if
(
$this
->
enableIDN
)
{
$view
->
registerAssetBundle
(
'punycode'
);
}
$options
=
array
(
'pattern'
=>
new
JsExpression
(
$this
->
pattern
),
'fullPattern'
=>
new
JsExpression
(
$this
->
fullPattern
),
...
...
yii/validators/InlineValidator.php
View file @
f7b8595f
...
...
@@ -79,12 +79,14 @@ class InlineValidator extends Validator
*
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script. Null if the validator does not support
* client-side validation.
* @see enableClientValidation
* @see \yii\web\ActiveForm::enableClientValidation
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
if
(
$this
->
clientValidate
!==
null
)
{
$method
=
$this
->
clientValidate
;
...
...
yii/validators/NumberValidator.php
View file @
f7b8595f
...
...
@@ -114,9 +114,11 @@ class NumberValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$label
=
$object
->
getAttributeLabel
(
$attribute
);
$value
=
$object
->
$attribute
;
...
...
yii/validators/RangeValidator.php
View file @
f7b8595f
...
...
@@ -81,9 +81,11 @@ class RangeValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$range
=
array
();
foreach
(
$this
->
range
as
$value
)
{
...
...
yii/validators/RegularExpressionValidator.php
View file @
f7b8595f
...
...
@@ -79,10 +79,12 @@ class RegularExpressionValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @throws InvalidConfigException if the "pattern" is not a valid regular expression
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$pattern
=
$this
->
pattern
;
$pattern
=
preg_replace
(
'/\\\\x\{?([0-9a-fA-F]+)\}?/'
,
'\u$1'
,
$pattern
);
...
...
yii/validators/RequiredValidator.php
View file @
f7b8595f
...
...
@@ -102,9 +102,11 @@ class RequiredValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$options
=
array
();
if
(
$this
->
requiredValue
!==
null
)
{
...
...
yii/validators/StringValidator.php
View file @
f7b8595f
...
...
@@ -126,9 +126,11 @@ class StringValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
$label
=
$object
->
getAttributeLabel
(
$attribute
);
$value
=
$object
->
$attribute
;
...
...
yii/validators/UrlValidator.php
View file @
f7b8595f
...
...
@@ -110,11 +110,17 @@ class UrlValidator extends Validator
* Returns the JavaScript needed for performing client-side validation.
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script.
* @see \yii\Web\ActiveForm::enableClientValidation
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
if
(
$this
->
enableIDN
)
{
$view
->
registerAssetBundle
(
'punycode'
);
}
if
(
strpos
(
$this
->
pattern
,
'{schemes}'
)
!==
false
)
{
$pattern
=
str_replace
(
'{schemes}'
,
'('
.
implode
(
'|'
,
$this
->
validSchemes
)
.
')'
,
$this
->
pattern
);
}
else
{
...
...
yii/validators/Validator.php
View file @
f7b8595f
...
...
@@ -211,11 +211,13 @@ abstract class Validator extends Component
*
* @param \yii\base\Model $object the data object being validated
* @param string $attribute the name of the attribute to be validated.
* @param \yii\base\View $view the view object that is going to be used to render views or view files
* containing a model form with this validator applied.
* @return string the client-side validation script. Null if the validator does not support
* client-side validation.
* @see \yii\web\ActiveForm::enableClientValidation
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
,
$view
)
{
return
null
;
}
...
...
yii/widgets/ActiveField.php
View file @
f7b8595f
...
...
@@ -11,8 +11,6 @@ use yii\db\ActiveRecord;
use
yii\helpers\Html
;
use
yii\base\Model
;
use
yii\web\JsExpression
;
use
yii\validators\EmailValidator
;
use
yii\validators\UrlValidator
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -123,13 +121,6 @@ class ActiveField extends Component
}
$options
[
'class'
]
=
implode
(
' '
,
$class
);
foreach
(
$this
->
model
->
getActiveValidators
(
$attribute
)
as
$validator
)
{
if
((
$validator
instanceof
EmailValidator
||
$validator
instanceof
UrlValidator
)
&&
$validator
->
enableIDN
)
{
$this
->
form
->
view
->
registerAssetBundle
(
'punycode'
);
break
;
}
}
return
Html
::
beginTag
(
$this
->
tag
,
$options
);
}
...
...
@@ -147,7 +138,7 @@ class ActiveField extends Component
$validators
=
array
();
foreach
(
$this
->
model
->
getActiveValidators
(
$attribute
)
as
$validator
)
{
/** @var \yii\validators\Validator $validator */
$js
=
$validator
->
clientValidateAttribute
(
$this
->
model
,
$attribute
);
$js
=
$validator
->
clientValidateAttribute
(
$this
->
model
,
$attribute
,
$this
->
form
->
getView
()
);
if
(
$validator
->
enableClientValidation
&&
$js
!=
''
)
{
$validators
[]
=
$js
;
}
...
...
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