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
6f42e87e
Commit
6f42e87e
authored
Aug 14, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Html::error().
parent
cd84653f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
14 deletions
+29
-14
HtmlBase.php
framework/yii/helpers/HtmlBase.php
+24
-0
ActiveField.php
framework/yii/widgets/ActiveField.php
+5
-14
No files found.
framework/yii/helpers/HtmlBase.php
View file @
6f42e87e
...
@@ -935,6 +935,30 @@ class HtmlBase
...
@@ -935,6 +935,30 @@ class HtmlBase
}
}
/**
/**
* Generates a tag that contains the first validation error of the specified model attribute.
* Note that even if there is no validation error, this method will still return an empty error tag.
* @param Model $model the model object
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
* about attribute expression.
* @param array $options the tag options in terms of name-value pairs. The values will be HTML-encoded
* using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
*
* The following options are specially handled:
*
* - tag: this specifies the tag name. If not set, "p" will be used.
*
* @return string the generated label tag
*/
public
static
function
error
(
$model
,
$attribute
,
$options
=
array
())
{
$attribute
=
static
::
getAttributeName
(
$attribute
);
$error
=
$model
->
getFirstError
(
$attribute
);
$tag
=
isset
(
$options
[
'tag'
])
?
$options
[
'tag'
]
:
'p'
;
unset
(
$options
[
'tag'
]);
return
Html
::
tag
(
$tag
,
Html
::
encode
(
$error
),
$options
);
}
/**
* Generates an input tag for the given model attribute.
* Generates an input tag for the given model attribute.
* This method will generate the "name" and "value" tag attributes automatically for the model attribute
* This method will generate the "name" and "value" tag attributes automatically for the model attribute
* unless they are explicitly specified in `$options`.
* unless they are explicitly specified in `$options`.
...
...
framework/yii/widgets/ActiveField.php
View file @
6f42e87e
...
@@ -146,7 +146,6 @@ class ActiveField extends Component
...
@@ -146,7 +146,6 @@ class ActiveField extends Component
protected
function
getClientOptions
()
protected
function
getClientOptions
()
{
{
$enableClientValidation
=
$this
->
enableClientValidation
||
$this
->
enableClientValidation
===
null
&&
$this
->
form
->
enableClientValidation
;
$enableClientValidation
=
$this
->
enableClientValidation
||
$this
->
enableClientValidation
===
null
&&
$this
->
form
->
enableClientValidation
;
$enableAjaxValidation
=
$this
->
enableAjaxValidation
||
$this
->
enableAjaxValidation
===
null
&&
$this
->
form
->
enableAjaxValidation
;
if
(
$enableClientValidation
)
{
if
(
$enableClientValidation
)
{
$attribute
=
Html
::
getAttributeName
(
$this
->
attribute
);
$attribute
=
Html
::
getAttributeName
(
$this
->
attribute
);
$validators
=
array
();
$validators
=
array
();
...
@@ -162,6 +161,7 @@ class ActiveField extends Component
...
@@ -162,6 +161,7 @@ class ActiveField extends Component
}
}
}
}
$enableAjaxValidation
=
$this
->
enableAjaxValidation
||
$this
->
enableAjaxValidation
===
null
&&
$this
->
form
->
enableAjaxValidation
;
if
(
$enableAjaxValidation
)
{
if
(
$enableAjaxValidation
)
{
$options
[
'enableAjaxValidation'
]
=
1
;
$options
[
'enableAjaxValidation'
]
=
1
;
}
}
...
@@ -169,12 +169,7 @@ class ActiveField extends Component
...
@@ -169,12 +169,7 @@ class ActiveField extends Component
if
(
$enableClientValidation
&&
!
empty
(
$options
[
'validate'
])
||
$enableAjaxValidation
)
{
if
(
$enableClientValidation
&&
!
empty
(
$options
[
'validate'
])
||
$enableAjaxValidation
)
{
$inputID
=
Html
::
getInputId
(
$this
->
model
,
$this
->
attribute
);
$inputID
=
Html
::
getInputId
(
$this
->
model
,
$this
->
attribute
);
$options
[
'name'
]
=
$inputID
;
$options
[
'name'
]
=
$inputID
;
$names
=
array
(
foreach
(
array
(
'validateOnChange'
,
'validateOnType'
,
'validationDelay'
)
as
$name
)
{
'validateOnChange'
,
'validateOnType'
,
'validationDelay'
,
);
foreach
(
$names
as
$name
)
{
$options
[
$name
]
=
$this
->
$name
===
null
?
$this
->
form
->
$name
:
$this
->
$name
;
$options
[
$name
]
=
$this
->
$name
===
null
?
$this
->
form
->
$name
:
$this
->
$name
;
}
}
$options
[
'container'
]
=
isset
(
$this
->
selectors
[
'container'
])
?
$this
->
selectors
[
'container'
]
:
".field-
$inputID
"
;
$options
[
'container'
]
=
isset
(
$this
->
selectors
[
'container'
])
?
$this
->
selectors
[
'container'
]
:
".field-
$inputID
"
;
...
@@ -216,22 +211,18 @@ class ActiveField extends Component
...
@@ -216,22 +211,18 @@ class ActiveField extends Component
* Note that even if there is no validation error, this method will still return an empty error tag.
* Note that even if there is no validation error, this method will still return an empty error tag.
* @param array $options the tag options in terms of name-value pairs. It will be merged with [[errorOptions]].
* @param array $options the tag options in terms of name-value pairs. It will be merged with [[errorOptions]].
* The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded
* The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded
* using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
* using [[
Html::
encode()]]. If a value is null, the corresponding attribute will not be rendered.
*
*
* The following options are specially handled:
* The following options are specially handled:
*
*
* - tag: this specifies the tag name. If not set, "
span
" will be used.
* - tag: this specifies the tag name. If not set, "
p
" will be used.
*
*
* @return string the generated label tag
* @return string the generated label tag
*/
*/
public
function
error
(
$options
=
array
())
public
function
error
(
$options
=
array
())
{
{
$options
=
array_merge
(
$this
->
errorOptions
,
$options
);
$options
=
array_merge
(
$this
->
errorOptions
,
$options
);
$attribute
=
Html
::
getAttributeName
(
$this
->
attribute
);
return
Html
::
error
(
$this
->
model
,
$this
->
attribute
,
$options
);
$error
=
$this
->
model
->
getFirstError
(
$attribute
);
$tag
=
isset
(
$options
[
'tag'
])
?
$options
[
'tag'
]
:
'span'
;
unset
(
$options
[
'tag'
]);
return
Html
::
tag
(
$tag
,
Html
::
encode
(
$error
),
$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