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
f245430e
Commit
f245430e
authored
Jan 11, 2018
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow overriding `horizontalCssClasses` when extending `\yii\bootstrap\ActiveField`
parent
1db3f49f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
3 deletions
+75
-3
ActiveField.php
ActiveField.php
+3
-3
CHANGELOG.md
CHANGELOG.md
+1
-0
ActiveFieldTest.php
tests/ActiveFieldTest.php
+48
-0
ExtendedActiveField.php
tests/data/ExtendedActiveField.php
+23
-0
No files found.
ActiveField.php
View file @
f245430e
...
...
@@ -110,7 +110,7 @@ class ActiveField extends \yii\widgets\ActiveField
* - 'error' the error grid class
* - 'hint' the hint grid class
*/
public
$horizontalCssClasses
;
public
$horizontalCssClasses
=
[]
;
/**
* @var string the template for checkboxes in default layout
*/
...
...
@@ -364,13 +364,13 @@ class ActiveField extends \yii\widgets\ActiveField
if
(
$layout
===
'horizontal'
)
{
$config
[
'template'
]
=
"
{
label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}\n{hint
}
"
;
$cssClasses
=
[
$cssClasses
=
array_merge
(
[
'offset'
=>
'col-sm-offset-3'
,
'label'
=>
'col-sm-3'
,
'wrapper'
=>
'col-sm-6'
,
'error'
=>
''
,
'hint'
=>
'col-sm-3'
,
];
]
,
$this
->
horizontalCssClasses
)
;
if
(
isset
(
$instanceConfig
[
'horizontalCssClasses'
]))
{
$cssClasses
=
ArrayHelper
::
merge
(
$cssClasses
,
$instanceConfig
[
'horizontalCssClasses'
]);
}
...
...
CHANGELOG.md
View file @
f245430e
...
...
@@ -5,6 +5,7 @@ Yii Framework 2 bootstrap extension Change Log
-----------------------
-
Bug #126: Fixed
`yii\bootstrap\ToggleButtonGroup`
toggles dropdown for both buttons in case
`split`
is enabled (klimov-paul)
-
Bug #136: Allow overriding
`horizontalCssClasses`
when extending
`\yii\bootstrap\ActiveField`
(mikehaertl, klimov-paul)
-
Enh #219: Add ability to use custom HTML in navbar-header (razvanphp)
-
Enh #171: Add ability to use a brandImage with the navbar (razvanphp)
-
Enh #227: Added
`yii\bootstrap\Collapse::$itemToggleOptions`
allowing setup custom collapse tag name and HTML options (mskayali, klimov-paul)
...
...
tests/ActiveFieldTest.php
View file @
f245430e
...
...
@@ -6,6 +6,7 @@ use yii\base\DynamicModel;
use
yii\bootstrap\ActiveField
;
use
yii\bootstrap\ActiveForm
;
use
Yii
;
use
yiiunit\extensions\bootstrap\data\ExtendedActiveField
;
class
ActiveFieldTest
extends
TestCase
{
...
...
@@ -110,4 +111,51 @@ HTML;
$this
->
assertContains
(
'data-attribute="test"'
,
$content
);
}
public
function
testHorizontalCssClasses
()
{
$this
->
helperForm
->
layout
=
'horizontal'
;
$activeField
=
new
ActiveField
([
'form'
=>
$this
->
helperForm
]);
$activeField
->
model
=
$this
->
helperModel
;
$activeField
->
attribute
=
$this
->
attributeName
;
$html
=
$activeField
->
render
();
$expectedHtml
=
<<<EXPECTED
<div class="form-group field-dynamicmodel-attributename">
<label class="control-label col-sm-3" for="dynamicmodel-attributename">Attribute Name</label>
<div class="col-sm-6">
<input type="text" id="dynamicmodel-attributename" class="form-control" name="DynamicModel[attributeName]">
<div class="help-block help-block-error "></div>
</div>
</div>
EXPECTED;
$this
->
assertEqualsWithoutLE
(
$expectedHtml
,
$html
);
}
/**
* @depends testHorizontalCssClasses
*/
public
function
testHorizontalCssClassesOverride
()
{
$this
->
helperForm
->
layout
=
'horizontal'
;
$activeField
=
new
ExtendedActiveField
([
'form'
=>
$this
->
helperForm
]);
$activeField
->
model
=
$this
->
helperModel
;
$activeField
->
attribute
=
$this
->
attributeName
;
$html
=
$activeField
->
render
();
$expectedHtml
=
<<<EXPECTED
<div class="form-group field-dynamicmodel-attributename">
<label class="control-label col-md-4" for="dynamicmodel-attributename">Attribute Name</label>
<div class="col-md-6">
<input type="text" id="dynamicmodel-attributename" class="form-control" name="DynamicModel[attributeName]">
<div class="help-block help-block-error col-md-3"></div>
</div>
</div>
EXPECTED;
$this
->
assertEqualsWithoutLE
(
$expectedHtml
,
$html
);
}
}
\ No newline at end of file
tests/data/ExtendedActiveField.php
0 → 100644
View file @
f245430e
<?php
namespace
yiiunit\extensions\bootstrap\data
;
use
yii\bootstrap\ActiveField
;
/**
* A customized extension from ActiveField
*
* @see \yiiunit\extensions\bootstrap\ActiveFieldTest::testHorizontalCssClassesOverride()
*
* @author Michael Härtl <haertl.mike@gmail.com>
*/
class
ExtendedActiveField
extends
ActiveField
{
public
$horizontalCssClasses
=
[
'offset'
=>
'col-md-offset-4'
,
'label'
=>
'col-md-4'
,
'wrapper'
=>
'col-md-6'
,
'error'
=>
'col-md-3'
,
'hint'
=>
'col-md-3'
,
];
}
\ No newline at end of file
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