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
4e7a33bc
Commit
4e7a33bc
authored
May 02, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished js validation for string validator.
parent
5069c29b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
25 deletions
+38
-25
yii.validation.js
framework/assets/yii.validation.js
+21
-0
StringValidator.php
framework/validators/StringValidator.php
+17
-25
No files found.
framework/assets/yii.validation.js
View file @
4e7a33bc
...
@@ -114,5 +114,26 @@ yii.validation = (function ($) {
...
@@ -114,5 +114,26 @@ yii.validation = (function ($) {
messages
.
push
(
options
.
message
);
messages
.
push
(
options
.
message
);
}
}
},
},
string
:
function
(
value
,
messages
,
options
)
{
if
(
options
.
skipOnEmpty
&&
isEmpty
(
value
))
{
return
;
}
if
(
typeof
value
!==
'string'
)
{
messages
.
push
(
options
.
message
);
return
;
}
if
(
options
.
min
!==
undefined
&&
value
.
length
<
options
.
min
)
{
messages
.
push
(
options
.
tooShort
);
}
if
(
options
.
max
!==
undefined
&&
value
.
length
>
options
.
max
)
{
messages
.
push
(
options
.
tooLong
);
}
if
(
options
.
is
!==
undefined
&&
value
.
length
!=
options
.
is
)
{
messages
.
push
(
options
.
is
);
}
}
};
};
})(
jQuery
);
})(
jQuery
);
framework/validators/StringValidator.php
View file @
4e7a33bc
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
yii\validators
;
namespace
yii\validators
;
use
Yii
;
use
Yii
;
use
yii\helpers\Html
;
/**
/**
* StringValidator validates that the attribute value is of certain length.
* StringValidator validates that the attribute value is of certain length.
...
@@ -132,56 +133,47 @@ class StringValidator extends Validator
...
@@ -132,56 +133,47 @@ 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
(
$notEqual
=
strtr
(
$this
->
notEqual
,
array
(
'{attribute}'
=>
$label
,
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{value}'
=>
$value
,
'{length}'
=>
$this
->
is
,
'{length}'
=>
$this
->
is
,
));
));
$tooShort
=
strtr
(
$this
->
tooShort
,
array
(
$tooShort
=
strtr
(
$this
->
tooShort
,
array
(
'{attribute}'
=>
$label
,
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{value}'
=>
$value
,
'{min}'
=>
$this
->
min
,
'{min}'
=>
$this
->
min
,
));
));
$tooLong
=
strtr
(
$this
->
tooLong
,
array
(
$tooLong
=
strtr
(
$this
->
tooLong
,
array
(
'{attribute}'
=>
$label
,
'{attribute}'
=>
$label
,
'{value}'
=>
$value
,
'{value}'
=>
$value
,
'{max}'
=>
$this
->
max
,
'{max}'
=>
$this
->
max
,
));
));
$js
=
''
;
$options
=
array
(
'message'
=>
Html
::
encode
(
$message
),
'notEqual'
=>
Html
::
encode
(
$notEqual
),
'tooShort'
=>
Html
::
encode
(
$tooShort
),
'tooLong'
=>
Html
::
encode
(
$tooLong
),
);
if
(
$this
->
min
!==
null
)
{
if
(
$this
->
min
!==
null
)
{
$js
.=
"
$options
[
'min'
]
=
$this
->
min
;
if(value.length<
{
$this
->
min
}
) {
messages.push("
.
json_encode
(
$tooShort
)
.
");
}
"
;
}
}
if
(
$this
->
max
!==
null
)
{
if
(
$this
->
max
!==
null
)
{
$js
.=
"
$options
[
'max'
]
=
$this
->
max
;
if(value.length>
{
$this
->
max
}
) {
messages.push("
.
json_encode
(
$tooLong
)
.
");
}
"
;
}
}
if
(
$this
->
is
!==
null
)
{
if
(
$this
->
is
!==
null
)
{
$js
.=
"
$options
[
'is'
]
=
$this
->
is
;
if(value.length!=
{
$this
->
is
}
) {
messages.push("
.
json_encode
(
$notEqual
)
.
");
}
"
;
}
}
if
(
$this
->
skipOnEmpty
)
{
if
(
$this
->
skipOnEmpty
)
{
$js
=
"
$options
[
'skipOnEmpty'
]
=
1
;
if($.trim(value)!='') {
$js
}
"
;
}
}
return
$js
;
return
'yii.validation.string(value, messages, '
.
json_encode
(
$options
)
.
');'
;
}
}
}
}
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