Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
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
夏彬
yii2bootstrap
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
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
220 additions
and
238 deletions
+220
-238
yii.activeForm.js
framework/assets/yii.activeForm.js
+161
-217
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
...
@@ -101,12 +101,6 @@ abstract class Validator extends Component
...
@@ -101,12 +101,6 @@ abstract class Validator extends Component
*/
*/
public
$skipOnEmpty
=
true
;
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.
* Validates a single attribute.
* Child classes must implement this method to provide the actual validation logic.
* Child classes must implement this method to provide the actual validation logic.
...
@@ -211,7 +205,6 @@ abstract class Validator extends Component
...
@@ -211,7 +205,6 @@ abstract class Validator extends Component
* @param string $attribute the name of the attribute to be validated.
* @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
* @return string the client-side validation script. Null if the validator does not support
* client-side validation.
* client-side validation.
* @see enableClientValidation
* @see \yii\web\ActiveForm::enableClientValidation
* @see \yii\web\ActiveForm::enableClientValidation
*/
*/
public
function
clientValidateAttribute
(
$object
,
$attribute
)
public
function
clientValidateAttribute
(
$object
,
$attribute
)
...
...
framework/widgets/ActiveField.php
View file @
86330471
...
@@ -10,6 +10,7 @@ namespace yii\widgets;
...
@@ -10,6 +10,7 @@ namespace yii\widgets;
use
yii\base\Component
;
use
yii\base\Component
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\base\Model
;
use
yii\base\Model
;
use
yii\helpers\JsExpression
;
/**
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
...
@@ -60,15 +61,39 @@ class ActiveField extends Component
...
@@ -60,15 +61,39 @@ class ActiveField extends Component
public
function
begin
()
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
;
$options
=
$this
->
options
;
$class
=
isset
(
$options
[
'class'
])
?
array
(
$options
[
'class'
])
:
array
();
$class
=
isset
(
$options
[
'class'
])
?
array
(
$options
[
'class'
])
:
array
();
$class
[]
=
'field-'
.
Html
::
getInputId
(
$this
->
model
,
$this
->
attribute
)
;
$class
[]
=
"field-
$inputID
"
;
if
(
$this
->
model
->
isAttributeRequired
(
$
this
->
attribute
))
{
if
(
$this
->
model
->
isAttributeRequired
(
$attribute
))
{
$class
[]
=
$this
->
form
->
requiredCssClass
;
$class
[]
=
$this
->
form
->
requiredCssClass
;
}
}
if
(
$this
->
model
->
hasErrors
(
$
this
->
attribute
))
{
if
(
$this
->
model
->
hasErrors
(
$attribute
))
{
$class
[]
=
$this
->
form
->
errorCssClass
;
$class
[]
=
$this
->
form
->
errorCssClass
;
}
}
$options
[
'class'
]
=
implode
(
' '
,
$class
);
$options
[
'class'
]
=
implode
(
' '
,
$class
);
return
Html
::
beginTag
(
$this
->
tag
,
$options
);
return
Html
::
beginTag
(
$this
->
tag
,
$options
);
}
}
...
...
framework/widgets/ActiveForm.php
View file @
86330471
...
@@ -11,6 +11,7 @@ use Yii;
...
@@ -11,6 +11,7 @@ use Yii;
use
yii\base\Widget
;
use
yii\base\Widget
;
use
yii\base\Model
;
use
yii\base\Model
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\helpers\Json
;
/**
/**
* ActiveForm ...
* ActiveForm ...
...
@@ -40,18 +41,21 @@ class ActiveForm extends Widget
...
@@ -40,18 +41,21 @@ class ActiveForm extends Widget
* @see errorSummary()
* @see errorSummary()
*/
*/
public
$errorSummaryCssClass
=
'yii-error-summary'
;
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.
* @var array the default configuration used by [[field()]] when creating a new field object.
*/
*/
public
$fieldConfig
=
array
(
public
$fieldConfig
=
array
(
'class'
=>
'yii\widgets\ActiveField'
,
'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.
* @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
...
@@ -69,13 +73,22 @@ class ActiveForm extends Widget
*/
*/
public
$validatingCssClass
=
'validating'
;
public
$validatingCssClass
=
'validating'
;
public
$validationUrl
;
public
$validationDelay
;
public
$validateOnChange
;
public
$validateOnType
;
public
$attributes
=
array
();
/**
/**
* Initializes the widget.
* Initializes the widget.
* This renders the form open tag.
* This renders the form open tag.
*/
*/
public
function
init
()
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
);
echo
Html
::
beginForm
(
$this
->
action
,
$this
->
method
,
$this
->
options
);
}
}
...
@@ -85,11 +98,18 @@ class ActiveForm extends Widget
...
@@ -85,11 +98,18 @@ class ActiveForm extends Widget
*/
*/
public
function
run
()
public
function
run
()
{
{
$id
=
$this
->
getId
();
$id
=
$this
->
options
[
'id'
];
$options
=
array
();
$options
=
array
(
$options
=
json_encode
(
$options
);
'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
->
registerAssetBundle
(
'yii/form'
);
$this
->
view
->
registerJs
(
"jQuery('#
$id
').yii
.form(
$options
);"
);
$this
->
view
->
registerJs
(
"jQuery('#
$id
').yii
ActiveForm(
$attributes
,
$options
);"
);
echo
Html
::
endForm
();
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