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
08c3f90d
Commit
08c3f90d
authored
May 02, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished js validation for number validator.
parent
4e7a33bc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
56 deletions
+62
-56
yii.validation.js
framework/assets/yii.validation.js
+19
-1
NumberValidator.php
framework/validators/NumberValidator.php
+23
-31
RegularExpressionValidator.php
framework/validators/RegularExpressionValidator.php
+1
-0
StringValidator.php
framework/validators/StringValidator.php
+19
-24
No files found.
framework/assets/yii.validation.js
View file @
08c3f90d
...
@@ -86,7 +86,7 @@ yii.validation = (function ($) {
...
@@ -86,7 +86,7 @@ yii.validation = (function ($) {
return
;
return
;
}
}
if
(
!
value
.
match
(
options
.
pattern
))
{
if
(
!
options
.
not
&&
!
value
.
match
(
options
.
pattern
)
||
options
.
not
&&
value
.
match
(
options
.
pattern
))
{
messages
.
push
(
options
.
message
)
messages
.
push
(
options
.
message
)
}
}
},
},
...
@@ -134,6 +134,24 @@ yii.validation = (function ($) {
...
@@ -134,6 +134,24 @@ yii.validation = (function ($) {
if
(
options
.
is
!==
undefined
&&
value
.
length
!=
options
.
is
)
{
if
(
options
.
is
!==
undefined
&&
value
.
length
!=
options
.
is
)
{
messages
.
push
(
options
.
is
);
messages
.
push
(
options
.
is
);
}
}
},
number
:
function
(
value
,
messages
,
options
)
{
if
(
options
.
skipOnEmpty
&&
isEmpty
(
value
))
{
return
;
}
if
(
typeof
value
===
'string'
&&
!
value
.
match
(
options
.
pattern
))
{
messages
.
push
(
options
.
message
);
return
;
}
if
(
options
.
min
!==
undefined
&&
value
<
options
.
min
)
{
messages
.
push
(
options
.
tooSmall
);
}
if
(
options
.
max
!==
undefined
&&
value
>
options
.
max
)
{
messages
.
push
(
options
.
tooBig
);
}
}
}
};
};
})(
jQuery
);
})(
jQuery
);
framework/validators/NumberValidator.php
View file @
08c3f90d
...
@@ -8,6 +8,9 @@
...
@@ -8,6 +8,9 @@
namespace
yii\validators
;
namespace
yii\validators
;
use
Yii
;
use
Yii
;
use
yii\helpers\Html
;
use
yii\helpers\JsExpression
;
use
yii\helpers\Json
;
/**
/**
* NumberValidator validates that the attribute value is a number.
* NumberValidator validates that the attribute value is a number.
...
@@ -116,48 +119,36 @@ class NumberValidator extends Validator
...
@@ -116,48 +119,36 @@ class NumberValidator extends Validator
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
)
{
{
$label
=
$object
->
getAttributeLabel
(
$attribute
);
$label
=
$object
->
getAttributeLabel
(
$attribute
);
$message
=
strtr
(
$this
->
message
,
array
(
$value
=
$object
->
$attribute
;
'{attribute}'
=>
$label
,
));
$options
=
array
(
'pattern'
=>
new
JsExpression
(
$this
->
integerOnly
?
$this
->
integerPattern
:
$this
->
numberPattern
),
'message'
=>
Html
::
encode
(
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
))),
);
$pattern
=
$this
->
integerOnly
?
$this
->
integerPattern
:
$this
->
numberPattern
;
$js
=
"
if(!value.match(
$pattern
)) {
messages.push("
.
json_encode
(
$message
)
.
");
}
"
;
if
(
$this
->
min
!==
null
)
{
if
(
$this
->
min
!==
null
)
{
$tooSmall
=
strtr
(
$this
->
tooSmall
,
array
(
$options
[
'min'
]
=
$this
->
min
;
$options
[
'tooSmall'
]
=
Html
::
encode
(
strtr
(
$this
->
tooSmall
,
array
(
'{attribute}'
=>
$label
,
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{min}'
=>
$this
->
min
,
'{min}'
=>
$this
->
min
,
));
)));
$js
.=
"
if(value<
{
$this
->
min
}
) {
messages.push("
.
json_encode
(
$tooSmall
)
.
");
}
"
;
}
}
if
(
$this
->
max
!==
null
)
{
if
(
$this
->
max
!==
null
)
{
$tooBig
=
strtr
(
$this
->
tooBig
,
array
(
$options
[
'max'
]
=
$this
->
max
;
$options
[
'tooBig'
]
=
Html
::
encode
(
strtr
(
$this
->
tooBig
,
array
(
'{attribute}'
=>
$label
,
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{max}'
=>
$this
->
max
,
'{max}'
=>
$this
->
max
,
));
)));
$js
.=
"
if(value>
{
$this
->
max
}
) {
messages.push("
.
json_encode
(
$tooBig
)
.
");
}
"
;
}
}
if
(
$this
->
skipOnEmpty
)
{
if
(
$this
->
skipOnEmpty
)
{
$js
=
"
$options
[
'skipOnEmpty'
]
=
1
;
if(jQuery.trim(value)!='') {
$js
}
"
;
}
}
return
$js
;
return
'yii.validation.number(value, messages, '
.
Json
::
encode
(
$options
)
.
');'
;
}
}
}
}
\ No newline at end of file
framework/validators/RegularExpressionValidator.php
View file @
08c3f90d
...
@@ -100,6 +100,7 @@ class RegularExpressionValidator extends Validator
...
@@ -100,6 +100,7 @@ class RegularExpressionValidator extends Validator
$options
=
array
(
$options
=
array
(
'pattern'
=>
new
JsExpression
(
$pattern
),
'pattern'
=>
new
JsExpression
(
$pattern
),
'not'
=>
$this
->
not
,
'message'
=>
Html
::
encode
(
strtr
(
$this
->
message
,
array
(
'message'
=>
Html
::
encode
(
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{attribute}'
=>
$object
->
getAttributeLabel
(
$attribute
),
'{value}'
=>
$object
->
$attribute
,
'{value}'
=>
$object
->
$attribute
,
...
...
framework/validators/StringValidator.php
View file @
08c3f90d
...
@@ -133,41 +133,36 @@ class StringValidator extends Validator
...
@@ -133,41 +133,36 @@ class StringValidator extends Validator
$label
=
$object
->
getAttributeLabel
(
$attribute
);
$label
=
$object
->
getAttributeLabel
(
$attribute
);
$value
=
$object
->
$attribute
;
$value
=
$object
->
$attribute
;
$message
=
strtr
(
$this
->
message
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
));
$notEqual
=
strtr
(
$this
->
notEqual
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{length}'
=>
$this
->
is
,
));
$tooShort
=
strtr
(
$this
->
tooShort
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{min}'
=>
$this
->
min
,
));
$tooLong
=
strtr
(
$this
->
tooLong
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{max}'
=>
$this
->
max
,
));
$options
=
array
(
$options
=
array
(
'message'
=>
Html
::
encode
(
$message
),
'message'
=>
Html
::
encode
(
strtr
(
$this
->
message
,
array
(
'notEqual'
=>
Html
::
encode
(
$notEqual
)
,
'{attribute}'
=>
$label
,
'tooShort'
=>
Html
::
encode
(
$tooShort
)
,
'{value}'
=>
$value
,
'tooLong'
=>
Html
::
encode
(
$tooLong
),
))
),
);
);
if
(
$this
->
min
!==
null
)
{
if
(
$this
->
min
!==
null
)
{
$options
[
'min'
]
=
$this
->
min
;
$options
[
'min'
]
=
$this
->
min
;
$options
[
'tooShort'
]
=
Html
::
encode
(
strtr
(
$this
->
tooShort
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{min}'
=>
$this
->
min
,
)));
}
}
if
(
$this
->
max
!==
null
)
{
if
(
$this
->
max
!==
null
)
{
$options
[
'max'
]
=
$this
->
max
;
$options
[
'max'
]
=
$this
->
max
;
$options
[
'tooLong'
]
=
Html
::
encode
(
strtr
(
$this
->
tooLong
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{max}'
=>
$this
->
max
,
)));
}
}
if
(
$this
->
is
!==
null
)
{
if
(
$this
->
is
!==
null
)
{
$options
[
'is'
]
=
$this
->
is
;
$options
[
'is'
]
=
$this
->
is
;
$options
[
'notEqual'
]
=
Html
::
encode
(
strtr
(
$this
->
notEqual
,
array
(
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{length}'
=>
$this
->
is
,
)));
}
}
if
(
$this
->
skipOnEmpty
)
{
if
(
$this
->
skipOnEmpty
)
{
$options
[
'skipOnEmpty'
]
=
1
;
$options
[
'skipOnEmpty'
]
=
1
;
...
...
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