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
aadcb59c
Commit
aadcb59c
authored
May 24, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ActiveField::widget().
parent
23611127
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
23 deletions
+49
-23
ActiveField.php
framework/yii/widgets/ActiveField.php
+49
-23
No files found.
framework/yii/widgets/ActiveField.php
View file @
aadcb59c
...
...
@@ -6,6 +6,7 @@
*/
namespace
yii\widgets
;
use
Yii
;
use
yii\base\Component
;
use
yii\db\ActiveRecord
;
use
yii\helpers\Html
;
...
...
@@ -101,6 +102,11 @@ class ActiveField extends Component
*/
public
$selectors
;
/**
* Renders the opening tag of the field container.
* @return string the rendering result.
*/
public
function
begin
()
{
$options
=
$this
->
getClientOptions
();
...
...
@@ -124,11 +130,19 @@ class ActiveField extends Component
return
Html
::
beginTag
(
$this
->
tag
,
$options
);
}
/**
* Renders the closing tag of the field container.
* @return string the rendering result.
*/
public
function
end
()
{
return
Html
::
endTag
(
$this
->
tag
);
}
/**
* Returns the JS options for the field.
* @return array the JS options
*/
protected
function
getClientOptions
()
{
$enableClientValidation
=
$this
->
enableClientValidation
||
$this
->
enableClientValidation
===
null
&&
$this
->
form
->
enableClientValidation
;
...
...
@@ -237,7 +251,7 @@ class ActiveField extends Component
}
/**
*
Generates an input tag for the given model attribute
.
*
Renders a field containing an input field
.
* @param string $type the input type (e.g. 'text', 'password')
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
...
...
@@ -250,12 +264,12 @@ class ActiveField extends Component
}
/**
*
Generates a text input tag for the given model attribute
.
*
Renders a field containing a text input
.
* This method will generate the "name" and "value" tag attributes automatically for the model attribute
* unless they are explicitly specified in `$options`.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* @return string the
generated input tag
* @return string the
rendering result
*/
public
function
textInput
(
$options
=
array
())
{
...
...
@@ -264,12 +278,12 @@ class ActiveField extends Component
}
/**
*
Generates a hidden input tag for the given model attribute
.
*
Renders a field containing a hidden input
.
* This method will generate the "name" and "value" tag attributes automatically for the model attribute
* unless they are explicitly specified in `$options`.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* @return string the
generated input tag
* @return string the
rendering result
*/
public
function
hiddenInput
(
$options
=
array
())
{
...
...
@@ -278,12 +292,12 @@ class ActiveField extends Component
}
/**
*
Generates a password input tag for the given model attribute
.
*
Renders a field containing a password input
.
* This method will generate the "name" and "value" tag attributes automatically for the model attribute
* unless they are explicitly specified in `$options`.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* @return string the
generated input tag
* @return string the
rendering result
*/
public
function
passwordInput
(
$options
=
array
())
{
...
...
@@ -292,12 +306,12 @@ class ActiveField extends Component
}
/**
*
Generates a file input tag for the given model attribute
.
*
Renders a field containing a file input
.
* This method will generate the "name" and "value" tag attributes automatically for the model attribute
* unless they are explicitly specified in `$options`.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* @return string the
generated input tag
* @return string the
rendering result
*/
public
function
fileInput
(
$options
=
array
())
{
...
...
@@ -306,11 +320,11 @@ class ActiveField extends Component
}
/**
*
Generates a textarea tag for the given model attribute
.
*
Renders a field containing a text area
.
* The model attribute value will be used as the content in the textarea.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* @return string the
generated textarea tag
* @return string the
rendering result
*/
public
function
textarea
(
$options
=
array
())
{
...
...
@@ -319,7 +333,7 @@ class ActiveField extends Component
}
/**
*
Generates a radio button tag for the given model attribute
.
*
Renders a field containing a radio button
.
* This method will generate the "name" tag attribute automatically unless it is explicitly specified in `$options`.
* This method will generate the "checked" tag attribute according to the model attribute value.
* @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
...
...
@@ -334,7 +348,7 @@ class ActiveField extends Component
* @param boolean $enclosedByLabel whether to enclose the radio within the label.
* If true, the method will still use [[template]] to layout the checkbox and the error message
* except that the radio is enclosed by the label tag.
* @return string the
generated radio button tag
* @return string the
rendering result
*/
public
function
radio
(
$options
=
array
(),
$enclosedByLabel
=
true
)
{
...
...
@@ -358,7 +372,7 @@ class ActiveField extends Component
}
/**
*
Generates a checkbox tag for the given model attribute
.
*
Renders a field containing a checkbox
.
* This method will generate the "name" tag attribute automatically unless it is explicitly specified in `$options`.
* This method will generate the "checked" tag attribute according to the model attribute value.
* @param array $options the tag options in terms of name-value pairs. The following options are specially handled:
...
...
@@ -373,7 +387,7 @@ class ActiveField extends Component
* @param boolean $enclosedByLabel whether to enclose the checkbox within the label.
* If true, the method will still use [[template]] to layout the checkbox and the error message
* except that the checkbox is enclosed by the label tag.
* @return string the
generated checkbox tag
* @return string the
rendering result
*/
public
function
checkbox
(
$options
=
array
(),
$enclosedByLabel
=
true
)
{
...
...
@@ -397,7 +411,7 @@ class ActiveField extends Component
}
/**
*
Generates a drop-down list for the given model attribute
.
*
Renders a field containing a drop-down list
.
* The selection of the drop-down list is taken from the value of the model attribute.
* @param array $items the option data items. The array keys are option values, and the array values
* are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too).
...
...
@@ -426,7 +440,7 @@ class ActiveField extends Component
* The rest of 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.
*
* @return string the
generated drop-down list tag
* @return string the
rendering result
*/
public
function
dropDownList
(
$items
,
$options
=
array
())
{
...
...
@@ -435,7 +449,7 @@ class ActiveField extends Component
}
/**
*
Generates
a list box.
*
Renders a field containing
a list box.
* The selection of the list box is taken from the value of the model attribute.
* @param array $items the option data items. The array keys are option values, and the array values
* are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too).
...
...
@@ -467,7 +481,7 @@ class ActiveField extends Component
* The rest of 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.
*
* @return string the
generated list box tag
* @return string the
rendering result
*/
public
function
listBox
(
$items
,
$options
=
array
())
{
...
...
@@ -476,7 +490,7 @@ class ActiveField extends Component
}
/**
*
Generates
a list of checkboxes.
*
Renders a field containing
a list of checkboxes.
* A checkbox list allows multiple selection, like [[listBox()]].
* As a result, the corresponding submitted value is an array.
* The selection of the checkbox list is taken from the value of the model attribute.
...
...
@@ -498,7 +512,7 @@ class ActiveField extends Component
* where $index is the zero-based index of the checkbox in the whole list; $label
* is the label for the checkbox; and $name, $value and $checked represent the name,
* value and the checked status of the checkbox input.
* @return string the
generated checkbox lis
t
* @return string the
rendering resul
t
*/
public
function
checkboxList
(
$items
,
$options
=
array
())
{
...
...
@@ -510,7 +524,7 @@ class ActiveField extends Component
}
/**
*
Generates
a list of radio buttons.
*
Renders a field containing
a list of radio buttons.
* A radio button list is like a checkbox list, except that it only allows single selection.
* The selection of the radio buttons is taken from the value of the model attribute.
* @param array $items the data item used to generate the radio buttons.
...
...
@@ -531,7 +545,7 @@ class ActiveField extends Component
* where $index is the zero-based index of the radio button in the whole list; $label
* is the label for the radio button; and $name, $value and $checked represent the name,
* value and the checked status of the radio button input.
* @return string the
generated radio button lis
t
* @return string the
rendering resul
t
*/
public
function
radioList
(
$items
,
$options
=
array
())
{
...
...
@@ -541,4 +555,16 @@ class ActiveField extends Component
.
'</div>'
);
}
/**
* Renders a field containing a widget.
* @param string $class the widget class name
* @param array $config name-value pairs that will be used to initialize the widget
* @return string the rendering result
*/
public
function
widget
(
$class
,
$config
=
array
())
{
/** @var \yii\base\Widget $class */
return
$this
->
render
(
$class
::
widget
(
$config
));
}
}
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