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
5c431b9d
Commit
5c431b9d
authored
Jun 06, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3698 from mikehaertl/master
Fix label() method and make more templates configurable
parents
ce70a4e0
65e18afe
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
8 deletions
+69
-8
ActiveField.php
extensions/bootstrap/ActiveField.php
+69
-8
No files found.
extensions/bootstrap/ActiveField.php
View file @
5c431b9d
...
@@ -35,8 +35,16 @@ use yii\helpers\ArrayHelper;
...
@@ -35,8 +35,16 @@ use yii\helpers\ArrayHelper;
* The wrapper tag is only used for some layouts and form elements.
* The wrapper tag is only used for some layouts and form elements.
*
*
* Note that some elements use slightly different defaults for [[template]] and other options.
* Note that some elements use slightly different defaults for [[template]] and other options.
* In particular the elements are [[checkbox()]], [[checkboxList()]] and [[radioList()]].
* You may want to override those predefined templates for checkboxes, radio buttons, checkboxLists
* So to further customize these elements you may want to pass your custom options.
* and radioLists in the [[\yii\widgets\ActiveForm::fieldConfig|fieldConfig]] of the
* [[\yii\widgets\ActiveForm]]:
*
* - [[checkboxTemplate]] the template for checkboxes in default layout
* - [[radioTemplate]] the template for radio buttons in default layout
* - [[horizontalCheckboxTemplate]] the template for checkboxes in horizontal layout
* - [[horizontalRadioTemplate]] the template for radio buttons in horizontal layout
* - [[inlineCheckboxListTemplate]] the template for inline checkboxLists
* - [[inlineRadioListTemplate]] the template for inline radioLists
*
*
* Example:
* Example:
*
*
...
@@ -109,6 +117,36 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -109,6 +117,36 @@ class ActiveField extends \yii\widgets\ActiveField
public
$horizontalCssClasses
;
public
$horizontalCssClasses
;
/**
/**
* @var string the template for checkboxes in default layout
*/
public
$checkboxTemplate
=
"<div class=
\"
checkbox
\"
>
\n
{
beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint
}
\n
</div>"
;
/**
* @var string the template for radios in default layout
*/
public
$radioTemplate
=
"<div class=
\"
radio
\"
>
\n
{
beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint
}
\n
</div>"
;
/**
* @var string the template for checkboxes in horizontal layout
*/
public
$horizontalCheckboxTemplate
=
"
{
beginWrapper
}
\n
<div class=
\"
checkbox
\"
>
\n
{
beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n</div>\n{error}\n{endWrapper}\n{hint
}
"
;
/**
* @var string the template for radio buttons in horizontal layout
*/
public
$horizontalRadioTemplate
=
"
{
beginWrapper
}
\n
<div class=
\"
radio
\"
>
\n
{
beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n</div>\n{error}\n{endWrapper}\n{hint
}
"
;
/**
* @var string the template for inline checkboxLists
*/
public
$inlineCheckboxListTemplate
=
"
{
label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}\n{hint
}
"
;
/**
* @var string the template for inline radioLists
*/
public
$inlineRadioListTemplate
=
"
{
label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}\n{hint
}
"
;
/**
* @var bool whether to render the error. Default is `true` except for layout `inline`.
* @var bool whether to render the error. Default is `true` except for layout `inline`.
*/
*/
public
$enableError
=
true
;
public
$enableError
=
true
;
...
@@ -167,20 +205,42 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -167,20 +205,42 @@ class ActiveField extends \yii\widgets\ActiveField
{
{
if
(
$enclosedByLabel
)
{
if
(
$enclosedByLabel
)
{
if
(
!
isset
(
$options
[
'template'
]))
{
if
(
!
isset
(
$options
[
'template'
]))
{
$this
->
template
=
$this
->
form
->
layout
===
'horizontal'
?
$this
->
horizontalCheckboxTemplate
:
$this
->
checkBoxTemplate
;
}
else
{
$this
->
template
=
$options
[
'template'
];
unset
(
$options
[
'template'
]);
}
if
(
$this
->
form
->
layout
===
'horizontal'
)
{
if
(
$this
->
form
->
layout
===
'horizontal'
)
{
$this
->
template
=
"
{
beginWrapper
}
\n
<div class=
\"
checkbox
\"
>
\n
{
beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n</div>\n{error}\n{endWrapper}\n{hint
}
"
;
Html
::
addCssClass
(
$this
->
wrapperOptions
,
$this
->
horizontalCssClasses
[
'offset'
]);
Html
::
addCssClass
(
$this
->
wrapperOptions
,
$this
->
horizontalCssClasses
[
'offset'
]);
}
else
{
$this
->
template
=
"<div class=
\"
checkbox
\"
>
\n
{
beginLabel}\n{input}\n{labelTitle}\n{endLabel}\n{error}\n{hint
}
\n
</div>"
;
}
}
$this
->
labelOptions
[
'class'
]
=
null
;
}
parent
::
checkbox
(
$options
,
false
);
return
$this
;
}
/**
* @inheritdoc
*/
public
function
radio
(
$options
=
[],
$enclosedByLabel
=
true
)
{
if
(
$enclosedByLabel
)
{
if
(
!
isset
(
$options
[
'template'
]))
{
$this
->
template
=
$this
->
form
->
layout
===
'horizontal'
?
$this
->
horizontalRadioTemplate
:
$this
->
radioTemplate
;
}
else
{
}
else
{
$this
->
template
=
$options
[
'template'
];
$this
->
template
=
$options
[
'template'
];
unset
(
$options
[
'template'
]);
unset
(
$options
[
'template'
]);
}
}
if
(
$this
->
form
->
layout
===
'horizontal'
)
{
Html
::
addCssClass
(
$this
->
wrapperOptions
,
$this
->
horizontalCssClasses
[
'offset'
]);
}
$this
->
labelOptions
[
'class'
]
=
null
;
$this
->
labelOptions
[
'class'
]
=
null
;
}
}
parent
::
checkbox
(
$options
,
false
);
parent
::
radio
(
$options
,
false
);
return
$this
;
return
$this
;
}
}
...
@@ -191,7 +251,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -191,7 +251,7 @@ class ActiveField extends \yii\widgets\ActiveField
{
{
if
(
$this
->
inline
)
{
if
(
$this
->
inline
)
{
if
(
!
isset
(
$options
[
'template'
]))
{
if
(
!
isset
(
$options
[
'template'
]))
{
$this
->
template
=
"
{
label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}\n{hint
}
"
;
$this
->
template
=
$this
->
inlineCheckboxListTemplate
;
}
else
{
}
else
{
$this
->
template
=
$options
[
'template'
];
$this
->
template
=
$options
[
'template'
];
unset
(
$options
[
'template'
]);
unset
(
$options
[
'template'
]);
...
@@ -214,7 +274,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -214,7 +274,7 @@ class ActiveField extends \yii\widgets\ActiveField
{
{
if
(
$this
->
inline
)
{
if
(
$this
->
inline
)
{
if
(
!
isset
(
$options
[
'template'
]))
{
if
(
!
isset
(
$options
[
'template'
]))
{
$this
->
template
=
"
{
label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}\n{hint
}
"
;
$this
->
template
=
$this
->
inlineRadioListTemplate
;
}
else
{
}
else
{
$this
->
template
=
$options
[
'template'
];
$this
->
template
=
$options
[
'template'
];
unset
(
$options
[
'template'
]);
unset
(
$options
[
'template'
]);
...
@@ -241,6 +301,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -241,6 +301,7 @@ class ActiveField extends \yii\widgets\ActiveField
Html
::
addCssClass
(
$this
->
wrapperOptions
,
$this
->
horizontalCssClasses
[
'offset'
]);
Html
::
addCssClass
(
$this
->
wrapperOptions
,
$this
->
horizontalCssClasses
[
'offset'
]);
}
}
}
else
{
}
else
{
$this
->
enableLabel
=
true
;
$this
->
renderLabelParts
(
$label
,
$options
);
$this
->
renderLabelParts
(
$label
,
$options
);
parent
::
label
(
$label
,
$options
);
parent
::
label
(
$label
,
$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