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
3b3beca0
Commit
3b3beca0
authored
Apr 09, 2014
by
Michael Härtl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #3029: Implement ActiveForm and ActiveField
parent
307ad56b
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
421 additions
and
0 deletions
+421
-0
ActiveField.php
ActiveField.php
+319
-0
ActiveForm.php
ActiveForm.php
+101
-0
CHANGELOG.md
CHANGELOG.md
+1
-0
No files found.
ActiveField.php
0 → 100644
View file @
3b3beca0
This diff is collapsed.
Click to expand it.
ActiveForm.php
0 → 100644
View file @
3b3beca0
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\bootstrap
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
use
yii\base\InvalidConfigException
;
use
Yii
;
/**
* A Bootstrap 3 enhanced version of [[yii\widgets\ActiveForm]].
*
* This class mainly adds the [[layout]] property to choose a Bootstrap 3 form layout.
* So for example to render a horizontal form you would:
*
* ```php
* use yii\bootstrap\ActiveForm;
*
* $form = ActiveForm::begin(['layout' => 'horizontal'])
* ```
*
* This will set default values for the [[yii\bootstrap\ActiveField|ActiveField]]
* to render horizontal form fields. In particular the [[yii\bootstrap\ActiveField::template|template]]
* is set to `{label} {beginWrapper} {input} {error} {endWrapper} {hint}` and the
* [[yii\bootstrap\ActiveField::horizontalCssClasses|horizontalCssClasses]] are set to:
*
* ```php
* [
* 'offset' => 'col-sm-offset-3',
* 'label' => 'col-sm-3',
* 'wrapper' => 'col-sm-6',
* 'error' => '',
* 'hint' => 'col-sm-3',
* ]
* ```
*
* To get a different column layout in horizontal mode you can modify those options
* through [[fieldConfig]]:
*
*
* ```php
* $form = ActiveForm::begin([
* 'layout' => 'horizontal',
* 'fieldConfig' => [
* 'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
* 'horizontalCssClasses' => [
* 'label' => 'col-sm-4',
* 'offset' => 'col-sm-offset-4',
* 'wrapper' => 'col-sm-8',
* 'error' => '',
* 'hint' => '',
* ],
* ],
* ]);
* ```
*
* @see \yii\bootstrap\ActiveField for details on the [[fieldConfig]] options
* @see http://getbootstrap.com/css/#forms
*
* @author Michael Härtl <haertl.mike@gmail.com>
* @since 2.0
*/
class
ActiveForm
extends
\yii\widgets\ActiveForm
{
/**
* @var array HTML attributes for the form tag. Default is `['role' => 'form']`.
*/
public
$options
=
[
'role'
=>
'form'
];
/**
* @var string the form layout. Either 'standard' (default), 'horizontal' or 'inline'.
* By chosing a layout, an appropriate default field configuration is applied. This will
* render the form fields with slightly different markup for each layout. You can
* override these defaults through [[fieldConfig]].
* @see \yii\bootstrap\ActiveField for details on Bootstrap 3 field configuration
*/
public
$layout
=
'standard'
;
/**
* @inheritDoc
*/
public
function
init
()
{
if
(
!
in_array
(
$this
->
layout
,
[
'standard'
,
'horizontal'
,
'inline'
]))
{
throw
new
InvalidConfigException
(
'Invalid layout type: '
.
$this
->
layout
);
}
if
(
$this
->
layout
!==
'standard'
)
{
Html
::
addCssClass
(
$this
->
options
,
'form-'
.
$this
->
layout
);
}
if
(
!
isset
(
$this
->
fieldConfig
[
'class'
]))
{
$this
->
fieldConfig
[
'class'
]
=
ActiveField
::
className
();
}
return
parent
::
init
();
}
}
CHANGELOG.md
View file @
3b3beca0
...
@@ -4,6 +4,7 @@ Yii Framework 2 bootstrap extension Change Log
...
@@ -4,6 +4,7 @@ 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)
...
...
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