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
f7396fa0
Commit
f7396fa0
authored
Apr 11, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refacotring of bootstrap active field and form.
parent
8ac79a35
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
31 deletions
+31
-31
ActiveField.php
extensions/bootstrap/ActiveField.php
+19
-19
ActiveForm.php
extensions/bootstrap/ActiveForm.php
+10
-11
CHANGELOG.md
extensions/bootstrap/CHANGELOG.md
+1
-1
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
No files found.
extensions/bootstrap/ActiveField.php
View file @
f7396fa0
...
@@ -62,7 +62,7 @@ use yii\helpers\ArrayHelper;
...
@@ -62,7 +62,7 @@ use yii\helpers\ArrayHelper;
* ]
* ]
* ]);
* ]);
*
*
* // With
standard
layout you would use 'template' to size a specific field:
* // With
'default'
layout you would use 'template' to size a specific field:
* // echo $form->field($model, 'demo', [
* // echo $form->field($model, 'demo', [
* // 'template' => '{label} <div class="row"><div class="col-sm-4">{input}{error}{hint}</div></div>'
* // 'template' => '{label} <div class="row"><div class="col-sm-4">{input}{error}{hint}</div></div>'
* // ]);
* // ]);
...
@@ -84,12 +84,12 @@ use yii\helpers\ArrayHelper;
...
@@ -84,12 +84,12 @@ use yii\helpers\ArrayHelper;
class
ActiveField
extends
\yii\widgets\ActiveField
class
ActiveField
extends
\yii\widgets\ActiveField
{
{
/**
/**
* @var bool whether to render [[checkboxList()]] and [[radioList()]] inline.
Default is `false`.
* @var bool whether to render [[checkboxList()]] and [[radioList()]] inline.
*/
*/
public
$inline
=
false
;
public
$inline
=
false
;
/**
/**
* @var string|null optional template to render the `{input}` plac
he
older content
* @var string|null optional template to render the `{input}` plac
eh
older content
*/
*/
public
$inputTemplate
;
public
$inputTemplate
;
...
@@ -119,7 +119,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -119,7 +119,7 @@ class ActiveField extends \yii\widgets\ActiveField
public
$enableLabel
=
true
;
public
$enableLabel
=
true
;
/**
/**
* @inherit
D
oc
* @inherit
d
oc
*/
*/
public
function
__construct
(
$config
=
[])
public
function
__construct
(
$config
=
[])
{
{
...
@@ -129,7 +129,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -129,7 +129,7 @@ class ActiveField extends \yii\widgets\ActiveField
}
}
/**
/**
* @inherit
D
oc
* @inherit
d
oc
*/
*/
public
function
render
(
$content
=
null
)
public
function
render
(
$content
=
null
)
{
{
...
@@ -140,7 +140,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -140,7 +140,7 @@ class ActiveField extends \yii\widgets\ActiveField
$this
->
parts
[
'{beginWrapper}'
]
=
Html
::
beginTag
(
$tag
,
$options
);
$this
->
parts
[
'{beginWrapper}'
]
=
Html
::
beginTag
(
$tag
,
$options
);
$this
->
parts
[
'{endWrapper}'
]
=
Html
::
endTag
(
$tag
);
$this
->
parts
[
'{endWrapper}'
]
=
Html
::
endTag
(
$tag
);
}
}
if
(
$this
->
enableLabel
===
false
)
{
if
(
$this
->
enableLabel
===
false
)
{
$this
->
parts
[
'{label}'
]
=
''
;
$this
->
parts
[
'{label}'
]
=
''
;
$this
->
parts
[
'{beginLabel}'
]
=
''
;
$this
->
parts
[
'{beginLabel}'
]
=
''
;
$this
->
parts
[
'{labelTitle}'
]
=
''
;
$this
->
parts
[
'{labelTitle}'
]
=
''
;
...
@@ -148,7 +148,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -148,7 +148,7 @@ class ActiveField extends \yii\widgets\ActiveField
}
elseif
(
!
isset
(
$this
->
parts
[
'{beginLabel}'
]))
{
}
elseif
(
!
isset
(
$this
->
parts
[
'{beginLabel}'
]))
{
$this
->
renderLabelParts
();
$this
->
renderLabelParts
();
}
}
if
(
$this
->
enableError
===
false
)
{
if
(
$this
->
enableError
===
false
)
{
$this
->
parts
[
'{error}'
]
=
''
;
$this
->
parts
[
'{error}'
]
=
''
;
}
}
if
(
$this
->
inputTemplate
)
{
if
(
$this
->
inputTemplate
)
{
...
@@ -161,13 +161,13 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -161,13 +161,13 @@ class ActiveField extends \yii\widgets\ActiveField
}
}
/**
/**
* @inherit
D
oc
* @inherit
d
oc
*/
*/
public
function
checkbox
(
$options
=
[],
$enclosedByLabel
=
true
)
public
function
checkbox
(
$options
=
[],
$enclosedByLabel
=
true
)
{
{
if
(
$enclosedByLabel
)
{
if
(
$enclosedByLabel
)
{
if
(
!
isset
(
$options
[
'template'
]))
{
if
(
!
isset
(
$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
}
"
;
$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
{
}
else
{
...
@@ -182,7 +182,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -182,7 +182,7 @@ class ActiveField extends \yii\widgets\ActiveField
}
}
/**
/**
* @inherit
D
oc
* @inherit
d
oc
*/
*/
public
function
checkboxList
(
$items
,
$options
=
[])
public
function
checkboxList
(
$items
,
$options
=
[])
{
{
...
@@ -202,7 +202,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -202,7 +202,7 @@ class ActiveField extends \yii\widgets\ActiveField
}
}
/**
/**
* @inherit
D
oc
* @inherit
d
oc
*/
*/
public
function
radioList
(
$items
,
$options
=
[])
public
function
radioList
(
$items
,
$options
=
[])
{
{
...
@@ -222,13 +222,13 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -222,13 +222,13 @@ class ActiveField extends \yii\widgets\ActiveField
}
}
/**
/**
* @inherit
D
oc
* @inherit
d
oc
*/
*/
public
function
label
(
$label
=
null
,
$options
=
[])
public
function
label
(
$label
=
null
,
$options
=
[])
{
{
if
(
is_bool
(
$label
))
{
if
(
is_bool
(
$label
))
{
$this
->
enableLabel
=
$label
;
$this
->
enableLabel
=
$label
;
if
(
$label
===
false
&&
$this
->
form
->
layout
===
'horizontal'
)
{
if
(
$label
===
false
&&
$this
->
form
->
layout
===
'horizontal'
)
{
Html
::
addCssClass
(
$this
->
wrapperOptions
,
$this
->
horizontalCssClasses
[
'offset'
]);
Html
::
addCssClass
(
$this
->
wrapperOptions
,
$this
->
horizontalCssClasses
[
'offset'
]);
}
}
}
else
{
}
else
{
...
@@ -271,7 +271,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -271,7 +271,7 @@ class ActiveField extends \yii\widgets\ActiveField
$layout
=
$instanceConfig
[
'form'
]
->
layout
;
$layout
=
$instanceConfig
[
'form'
]
->
layout
;
if
(
$layout
===
'horizontal'
)
{
if
(
$layout
===
'horizontal'
)
{
$config
[
'template'
]
=
"
{
label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}\n{hint
}
"
;
$config
[
'template'
]
=
"
{
label}\n{beginWrapper}\n{input}\n{error}\n{endWrapper}\n{hint
}
"
;
$cssClasses
=
[
$cssClasses
=
[
'offset'
=>
'col-sm-offset-3'
,
'offset'
=>
'col-sm-offset-3'
,
...
@@ -285,10 +285,10 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -285,10 +285,10 @@ class ActiveField extends \yii\widgets\ActiveField
}
}
$config
[
'horizontalCssClasses'
]
=
$cssClasses
;
$config
[
'horizontalCssClasses'
]
=
$cssClasses
;
$config
[
'wrapperOptions'
]
=
[
'class'
=>
$cssClasses
[
'wrapper'
]];
$config
[
'wrapperOptions'
]
=
[
'class'
=>
$cssClasses
[
'wrapper'
]];
$config
[
'labelOptions'
]
=
[
'class'
=>
'control-label '
.
$cssClasses
[
'label'
]];
$config
[
'labelOptions'
]
=
[
'class'
=>
'control-label '
.
$cssClasses
[
'label'
]];
$config
[
'errorOptions'
]
=
[
'class'
=>
'help-block '
.
$cssClasses
[
'error'
]];
$config
[
'errorOptions'
]
=
[
'class'
=>
'help-block '
.
$cssClasses
[
'error'
]];
$config
[
'hintOptions'
]
=
[
'class'
=>
'help-block '
.
$cssClasses
[
'hint'
]
];
$config
[
'hintOptions'
]
=
[
'class'
=>
'help-block '
.
$cssClasses
[
'hint'
]
];
}
elseif
(
$layout
===
'inline'
)
{
}
elseif
(
$layout
===
'inline'
)
{
$config
[
'labelOptions'
]
=
[
'class'
=>
'sr-only'
];
$config
[
'labelOptions'
]
=
[
'class'
=>
'sr-only'
];
$config
[
'enableError'
]
=
false
;
$config
[
'enableError'
]
=
false
;
}
}
...
@@ -303,7 +303,7 @@ class ActiveField extends \yii\widgets\ActiveField
...
@@ -303,7 +303,7 @@ class ActiveField extends \yii\widgets\ActiveField
protected
function
renderLabelParts
(
$label
=
null
,
$options
=
[])
protected
function
renderLabelParts
(
$label
=
null
,
$options
=
[])
{
{
$options
=
array_merge
(
$this
->
labelOptions
,
$options
);
$options
=
array_merge
(
$this
->
labelOptions
,
$options
);
if
(
$label
===
null
)
{
if
(
$label
===
null
)
{
if
(
isset
(
$options
[
'label'
]))
{
if
(
isset
(
$options
[
'label'
]))
{
$label
=
$options
[
'label'
];
$label
=
$options
[
'label'
];
unset
(
$options
[
'label'
]);
unset
(
$options
[
'label'
]);
...
...
extensions/bootstrap/ActiveForm.php
View file @
f7396fa0
...
@@ -7,10 +7,9 @@
...
@@ -7,10 +7,9 @@
namespace
yii\bootstrap
;
namespace
yii\bootstrap
;
use
yii\helpers\ArrayHelper
;
use
Yii
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
Yii
;
/**
/**
* A Bootstrap 3 enhanced version of [[yii\widgets\ActiveForm]].
* A Bootstrap 3 enhanced version of [[yii\widgets\ActiveForm]].
...
@@ -73,29 +72,29 @@ class ActiveForm extends \yii\widgets\ActiveForm
...
@@ -73,29 +72,29 @@ class ActiveForm extends \yii\widgets\ActiveForm
public
$options
=
[
'role'
=>
'form'
];
public
$options
=
[
'role'
=>
'form'
];
/**
/**
* @var string the form layout. Either '
standard' (default)
, 'horizontal' or 'inline'.
* @var string the form layout. Either '
default'
, 'horizontal' or 'inline'.
* By chosing a layout, an appropriate default field configuration is applied. This will
* By cho
o
sing a layout, an appropriate default field configuration is applied. This will
* render the form fields with slightly different markup for each layout. You can
* render the form fields with slightly different markup for each layout. You can
* override these defaults through [[fieldConfig]].
* override these defaults through [[fieldConfig]].
* @see \yii\bootstrap\ActiveField for details on Bootstrap 3 field configuration
* @see \yii\bootstrap\ActiveField for details on Bootstrap 3 field configuration
*/
*/
public
$layout
=
'
standard
'
;
public
$layout
=
'
default
'
;
/**
/**
* @inherit
D
oc
* @inherit
d
oc
*/
*/
public
function
init
()
public
function
init
()
{
{
if
(
!
in_array
(
$this
->
layout
,
[
'
standard'
,
'horizontal'
,
'inline'
]))
{
if
(
!
in_array
(
$this
->
layout
,
[
'
default'
,
'horizontal'
,
'inline'
]))
{
throw
new
InvalidConfigException
(
'Invalid layout type: '
.
$this
->
layout
);
throw
new
InvalidConfigException
(
'Invalid layout type: '
.
$this
->
layout
);
}
}
if
(
$this
->
layout
!==
'standard
'
)
{
if
(
$this
->
layout
!==
'default
'
)
{
Html
::
addCssClass
(
$this
->
options
,
'form-'
.
$this
->
layout
);
Html
::
addCssClass
(
$this
->
options
,
'form-'
.
$this
->
layout
);
}
}
if
(
!
isset
(
$this
->
fieldConfig
[
'class'
]))
{
if
(
!
isset
(
$this
->
fieldConfig
[
'class'
]))
{
$this
->
fieldConfig
[
'class'
]
=
ActiveField
::
className
();
$this
->
fieldConfig
[
'class'
]
=
ActiveField
::
className
();
}
}
return
parent
::
init
();
parent
::
init
();
}
}
}
}
extensions/bootstrap/CHANGELOG.md
View file @
f7396fa0
...
@@ -4,7 +4,6 @@ Yii Framework 2 bootstrap extension Change Log
...
@@ -4,7 +4,6 @@ Yii Framework 2 bootstrap extension Change Log
2.
0.0 beta under development
2.
0.0 beta under development
----------------------------
----------------------------
-
Enh #3029: Added
`ActiveForm`
and
`ActiveField`
(mikehaertl)
-
Bug #2361:
`yii\bootstrap\NavBar::brandUrl`
should default to the home URL of application (qiangxue)
-
Bug #2361:
`yii\bootstrap\NavBar::brandUrl`
should default to the home URL of application (qiangxue)
-
Enh #1474: Added option to make NavBar 100% width (cebe)
-
Enh #1474: Added option to make NavBar 100% width (cebe)
-
Enh #1552: It is now possible to use multiple bootstrap NavBar in a single page (Alex-Code)
-
Enh #1552: It is now possible to use multiple bootstrap NavBar in a single page (Alex-Code)
...
@@ -17,6 +16,7 @@ Yii Framework 2 bootstrap extension Change Log
...
@@ -17,6 +16,7 @@ Yii Framework 2 bootstrap extension Change Log
-
Enh #2643: Add size attribute to Modal (tof06)
-
Enh #2643: Add size attribute to Modal (tof06)
-
Chg #1459: Update Collapse to use bootstrap 3 classes (tonydspaniard)
-
Chg #1459: Update Collapse to use bootstrap 3 classes (tonydspaniard)
-
Chg #1820: Update Progress to use bootstrap 3 markup (samdark)
-
Chg #1820: Update Progress to use bootstrap 3 markup (samdark)
-
New #3029: Added
`yii\bootstrap\ActiveForm`
and
`yii\bootstrap\ActiveField`
(mikehaertl)
2.
0.0-alpha, December 1, 2013
2.
0.0-alpha, December 1, 2013
-----------------------------
-----------------------------
...
...
framework/CHANGELOG.md
View file @
f7396fa0
...
@@ -294,6 +294,7 @@ Yii Framework 2 Change Log
...
@@ -294,6 +294,7 @@ Yii Framework 2 Change Log
-
New #2360: Added
`AttributeBehavior`
and
`BlameableBehavior`
, and renamed
`AutoTimestamp`
to
`TimestampBehavior`
(lucianobaraglia, qiangxue)
-
New #2360: Added
`AttributeBehavior`
and
`BlameableBehavior`
, and renamed
`AutoTimestamp`
to
`TimestampBehavior`
(lucianobaraglia, qiangxue)
-
New #2932: Added
`yii\web\ViewAction`
that allow you to render views based on GET parameter (samdark)
-
New #2932: Added
`yii\web\ViewAction`
that allow you to render views based on GET parameter (samdark)
-
New #2998: Added
`framework\log\SyslogTarget`
that is able to write log to syslog (miramir, samdark)
-
New #2998: Added
`framework\log\SyslogTarget`
that is able to write log to syslog (miramir, samdark)
-
New #3029: Added
`yii\bootstrap\ActiveForm`
and
`yii\bootstrap\ActiveField`
(mikehaertl)
-
New: Yii framework now comes with core messages in multiple languages
-
New: Yii framework now comes with core messages in multiple languages
-
New: Added
`yii\codeception\DbTestCase`
(qiangxue)
-
New: Added
`yii\codeception\DbTestCase`
(qiangxue)
-
New: Added
`yii\web\GroupUrlRule`
(qiangxue)
-
New: Added
`yii\web\GroupUrlRule`
(qiangxue)
...
...
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