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
86330471
Commit
86330471
authored
May 02, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
form wip
parent
b4925d78
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
21 deletions
+59
-21
yii.activeForm.js
framework/assets/yii.activeForm.js
+0
-0
Validator.php
framework/validators/Validator.php
+0
-7
ActiveField.php
framework/widgets/ActiveField.php
+28
-3
ActiveForm.php
framework/widgets/ActiveForm.php
+31
-11
No files found.
framework/assets/yii.activeForm.js
View file @
86330471
This diff is collapsed.
Click to expand it.
framework/validators/Validator.php
View file @
86330471
...
...
@@ -102,12 +102,6 @@ abstract class Validator extends Component
public
$skipOnEmpty
=
true
;
/**
* @var boolean whether to enable client-side validation. Defaults to null, meaning
* its actual value inherits from that of [[\yii\web\ActiveForm::enableClientValidation]].
*/
public
$enableClientValidation
;
/**
* Validates a single attribute.
* Child classes must implement this method to provide the actual validation logic.
* @param \yii\base\Model $object the data object to be validated
...
...
@@ -211,7 +205,6 @@ abstract class Validator extends Component
* @param string $attribute the name of the attribute to be validated.
* @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
)
...
...
framework/widgets/ActiveField.php
View file @
86330471
...
...
@@ -10,6 +10,7 @@ namespace yii\widgets;
use
yii\base\Component
;
use
yii\helpers\Html
;
use
yii\base\Model
;
use
yii\helpers\JsExpression
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -60,15 +61,39 @@ class ActiveField extends Component
public
function
begin
()
{
$inputID
=
Html
::
getInputId
(
$this
->
model
,
$this
->
attribute
);
$attribute
=
Html
::
getAttributeName
(
$this
->
attribute
);
$validators
=
array
();
foreach
(
$this
->
model
->
getValidators
(
$attribute
)
as
$validator
)
{
/** @var \yii\validators\Validator $validator */
if
((
$js
=
$validator
->
clientValidateAttribute
(
$this
->
model
,
$attribute
))
!=
''
)
{
$validators
[]
=
$js
;
}
}
$jsOptions
=
array
(
'name'
=>
$this
->
attribute
,
'container'
=>
".field-
$inputID
"
,
'input'
=>
"#
$inputID
"
,
'error'
=>
'.help-inline'
,
);
if
(
$validators
!==
array
())
{
$jsOptions
[
'validate'
]
=
new
JsExpression
(
"function(attribute, value, messages) {"
.
implode
(
''
,
$validators
)
.
'}'
);
}
$this
->
form
->
attributes
[
$this
->
attribute
]
=
$jsOptions
;
$options
=
$this
->
options
;
$class
=
isset
(
$options
[
'class'
])
?
array
(
$options
[
'class'
])
:
array
();
$class
[]
=
'field-'
.
Html
::
getInputId
(
$this
->
model
,
$this
->
attribute
)
;
if
(
$this
->
model
->
isAttributeRequired
(
$
this
->
attribute
))
{
$class
[]
=
"field-
$inputID
"
;
if
(
$this
->
model
->
isAttributeRequired
(
$attribute
))
{
$class
[]
=
$this
->
form
->
requiredCssClass
;
}
if
(
$this
->
model
->
hasErrors
(
$
this
->
attribute
))
{
if
(
$this
->
model
->
hasErrors
(
$attribute
))
{
$class
[]
=
$this
->
form
->
errorCssClass
;
}
$options
[
'class'
]
=
implode
(
' '
,
$class
);
return
Html
::
beginTag
(
$this
->
tag
,
$options
);
}
...
...
framework/widgets/ActiveForm.php
View file @
86330471
...
...
@@ -11,6 +11,7 @@ use Yii;
use
yii\base\Widget
;
use
yii\base\Model
;
use
yii\helpers\Html
;
use
yii\helpers\Json
;
/**
* ActiveForm ...
...
...
@@ -41,17 +42,20 @@ class ActiveForm extends Widget
*/
public
$errorSummaryCssClass
=
'yii-error-summary'
;
/**
* @var boolean whether to enable client-side data validation.
* Client-side validation will be performed by validators that support it
* (see [[\yii\validators\Validator::enableClientValidation]] and [[\yii\validators\Validator::clientValidateAttribute()]]).
*/
public
$enableClientValidation
=
true
;
/**
* @var array the default configuration used by [[field()]] when creating a new field object.
*/
public
$fieldConfig
=
array
(
'class'
=>
'yii\widgets\ActiveField'
,
);
/**
* @var boolean whether to enable client-side data validation.
* Client-side validation will be performed by validators that support it
* (see [[\yii\validators\Validator::enableClientValidation]] and [[\yii\validators\Validator::clientValidateAttribute()]]).
*/
public
$enableClientValidation
=
true
;
public
$enableAjaxValidation
=
false
;
/**
* @var string the CSS class that is added to a field container when the associated attribute is required.
*/
...
...
@@ -69,13 +73,22 @@ class ActiveForm extends Widget
*/
public
$validatingCssClass
=
'validating'
;
public
$validationUrl
;
public
$validationDelay
;
public
$validateOnChange
;
public
$validateOnType
;
public
$attributes
=
array
();
/**
* Initializes the widget.
* This renders the form open tag.
*/
public
function
init
()
{
$this
->
options
[
'id'
]
=
$this
->
getId
();
if
(
!
isset
(
$this
->
options
[
'id'
]))
{
$this
->
options
[
'id'
]
=
$this
->
getId
();
}
echo
Html
::
beginForm
(
$this
->
action
,
$this
->
method
,
$this
->
options
);
}
...
...
@@ -85,11 +98,18 @@ class ActiveForm extends Widget
*/
public
function
run
()
{
$id
=
$this
->
getId
();
$options
=
array
();
$options
=
json_encode
(
$options
);
$id
=
$this
->
options
[
'id'
];
$options
=
array
(
'enableClientValidation'
=>
$this
->
enableClientValidation
,
'enableAjaxValidation'
=>
$this
->
enableAjaxValidation
,
'errorCssClass'
=>
$this
->
errorCssClass
,
'successCssClass'
=>
$this
->
successCssClass
,
'validatingCssClass'
=>
$this
->
validatingCssClass
,
);
$options
=
Json
::
encode
(
$options
);
$attributes
=
Json
::
encode
(
$this
->
attributes
);
$this
->
view
->
registerAssetBundle
(
'yii/form'
);
$this
->
view
->
registerJs
(
"jQuery('#
$id
').yii
.form(
$options
);"
);
$this
->
view
->
registerJs
(
"jQuery('#
$id
').yii
ActiveForm(
$attributes
,
$options
);"
);
echo
Html
::
endForm
();
}
...
...
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