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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
c0746f06
Commit
c0746f06
authored
Jun 29, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #588: Added afterValidate to ActiveForm.
parent
1a02a4d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
yii.activeForm.js
framework/yii/assets/yii.activeForm.js
+6
-0
ActiveForm.php
framework/yii/widgets/ActiveForm.php
+38
-0
No files found.
framework/yii/assets/yii.activeForm.js
View file @
c0746f06
...
...
@@ -41,6 +41,9 @@
// a callback that is called before validating each attribute. The signature of the callback should be:
// function ($form, attribute, messages) { ...return false to cancel the validation...}
beforeValidate
:
undefined
,
// a callback that is called after an attribute is validated. The signature of the callback should be:
// function ($form, attribute, messages)
afterValidate
:
undefined
,
// the GET parameter name indicating an AJAX-based validation
ajaxVar
:
'ajax'
};
...
...
@@ -333,6 +336,9 @@
$input
=
findInput
(
$form
,
attribute
),
hasError
=
false
;
if
(
data
.
settings
.
afterValidate
)
{
data
.
settings
.
afterValidate
(
$form
,
attribute
,
messages
);
}
attribute
.
status
=
1
;
if
(
$input
.
length
)
{
hasError
=
messages
&&
$
.
isArray
(
messages
[
attribute
.
name
])
&&
messages
[
attribute
.
name
].
length
;
...
...
framework/yii/widgets/ActiveForm.php
View file @
c0746f06
...
...
@@ -12,6 +12,7 @@ use yii\base\Widget;
use
yii\base\Model
;
use
yii\helpers\Html
;
use
yii\helpers\Json
;
use
yii\web\JsExpression
;
/**
* ActiveForm ...
...
...
@@ -103,6 +104,38 @@ class ActiveForm extends Widget
*/
public
$ajaxVar
=
'ajax'
;
/**
* @var string|JsExpression a JS callback that will be called when the form is being submitted.
* The signature of the callback should be:
*
* ~~~
* function ($form) {
* ...return false to cancel submission...
* }
* ~~~
*/
public
$beforeSubmit
;
/**
* @var string|JsExpression a JS callback that is called before validating an attribute.
* The signature of the callback should be:
*
* ~~~
* function ($form, attribute, messages) {
* ...return false to cancel the validation...
* }
* ~~~
*/
public
$beforeValidate
;
/**
* @var string|JsExpression a JS callback that is called after validating an attribute.
* The signature of the callback should be:
*
* ~~~
* function ($form, attribute, messages) {
* }
* ~~~
*/
public
$afterValidate
;
/**
* @var array the client validation options for individual attributes. Each element of the array
* represents the validation options for a particular attribute.
* @internal
...
...
@@ -157,6 +190,11 @@ class ActiveForm extends Widget
if
(
$this
->
validationUrl
!==
null
)
{
$options
[
'validationUrl'
]
=
Html
::
url
(
$this
->
validationUrl
);
}
foreach
(
array
(
'beforeSubmit'
,
'beforeValidate'
,
'afterValidate'
)
as
$name
)
{
if
((
$value
=
$this
->
$name
)
!==
null
)
{
$options
[
$name
]
=
$value
instanceof
JsExpression
?
$value
:
new
JsExpression
(
$value
);
}
}
return
$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