Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
Yii Bootstrap 3
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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Common
Yii Bootstrap 3
Commits
da78e227
Commit
da78e227
authored
Dec 19, 2012
by
Crisu83
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add initial form builder support
parent
0df5782b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
215 additions
and
0 deletions
+215
-0
TbForm.php
form/TbForm.php
+68
-0
TbFormButtonElement.php
form/TbFormButtonElement.php
+114
-0
TbFormInputElement.php
form/TbFormInputElement.php
+33
-0
No files found.
form/TbForm.php
0 → 100644
View file @
da78e227
<?php
/**
* TbForm class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright © Christoffer Niska 2012-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.form
* @since 2.0.0
*/
Yii
::
import
(
'bootstrap.form.*'
);
/**
* Bootstrap form builder.
*/
class
TbForm
extends
CForm
{
/**
* @var string the name of the class for representing a form input element.
*/
public
$buttonElementClass
=
'TbFormButtonElement'
;
/**
* @var string the name of the class for representing a form button element.
*/
public
$inputElementClass
=
'TbFormInputElement'
;
/**
* @var array the configuration used to create the active form widget.
*/
public
$activeForm
=
array
(
'class'
=>
'bootstrap.widgets.TbActiveForm'
);
/**
* Renders a single element which could be an input element, a sub-form, a string, or a button.
* @param mixed $element the form element to be rendered
* @return string the rendering result
*/
public
function
renderElement
(
$element
)
{
if
(
is_string
(
$element
))
{
if
((
$e
=
$this
[
$element
])
===
null
&&
(
$e
=
$this
->
getButtons
()
->
itemAt
(
$element
))
===
null
)
return
$element
;
else
$element
=
$e
;
}
if
(
$element
->
getVisible
())
{
if
(
$element
instanceof
CFormInputElement
)
{
if
(
$element
->
type
===
'hidden'
)
return
'<div class="hidden">'
.
$element
->
render
()
.
'</div>'
;
}
return
$element
->
render
();
}
return
''
;
}
/**
* Renders the {@link buttons} in this form.
* @return string the rendering result
*/
public
function
renderButtons
()
{
$output
=
''
;
foreach
(
$this
->
getButtons
()
as
$button
)
$output
.=
$this
->
renderElement
(
$button
);
return
$output
!==
''
?
'<div class="form-actions">'
.
$output
.
'</div>'
:
''
;
}
}
form/TbFormButtonElement.php
0 → 100644
View file @
da78e227
<?php
/**
* TbFormButtonElement class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright © Christoffer Niska 2012-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.form
* @since 2.0.0
*/
/**
* Bootstrap form builder button element.
*/
class
TbFormButtonElement
extends
CFormButtonElement
{
/**
* @var string the button callback types.
* @see TbButton::$buttonType
*/
public
$buttonType
;
/**
* @var string the button type.
* @see TbButton::$type
*/
public
$type
;
/**
* @var string the button size.
* @see TbButton::$size
*/
public
$size
;
/**
* @var string the button icon.
* @see TbButton::$icon
*/
public
$icon
;
/**
* @var string the button URL.
* @see TbButton::$url
*/
public
$url
;
/**
* @var boolean indicates whether the button should span the full width of the a parent.
*/
public
$block
=
false
;
/**
* @var boolean indicates whether the button is active.
*/
public
$active
=
false
;
/**
* @var boolean indicates whether the button is disabled.
*/
public
$disabled
=
false
;
/**
* @var boolean indicates whether to encode the label.
*/
public
$encodeLabel
=
true
;
/**
* @var boolean indicates whether to enable toggle.
*/
public
$toggle
;
/**
* @var string the text to display while loading.
*/
public
$loadingText
;
/**
* @var string the text to display when loading is complete.
*/
public
$completeText
;
/**
* @var array the dropdown button items.
*/
public
$items
=
array
();
/**
* @var array the HTML attributes for the widget container.
*/
public
$htmlOptions
=
array
();
/**
* @var array array the button ajax options.
* @see TbButton::$ajaxOptions
*/
public
$ajaxOptions
=
array
();
/**
* @var array the HTML attributes for the dropdown menu.
*/
public
$dropdownOptions
=
array
();
/**
* Returns this button.
* @return string the rendering result
*/
public
function
render
()
{
ob_start
();
$this
->
getParent
()
->
getOwner
()
->
widget
(
'bootstrap.widgets.TbButton'
,
array
(
'buttonType'
=>
isset
(
$this
->
buttonType
)
?
$this
->
buttonType
:
null
,
'type'
=>
isset
(
$this
->
type
)
?
$this
->
type
:
null
,
'size'
=>
isset
(
$this
->
size
)
?
$this
->
size
:
null
,
'icon'
=>
$this
->
icon
,
'label'
=>
$this
->
label
,
'url'
=>
$this
->
url
,
'block'
=>
$this
->
block
,
'active'
=>
$this
->
active
,
'disabled'
=>
$this
->
disabled
,
'encodeLabel'
=>
$this
->
encodeLabel
,
'toggle'
=>
$this
->
toggle
,
'loadingText'
=>
$this
->
loadingText
,
'completeText'
=>
$this
->
completeText
,
'items'
=>
$this
->
items
,
'htmlOptions'
=>
$this
->
htmlOptions
,
'ajaxOptions'
=>
$this
->
ajaxOptions
,
'dropdownOptions'
=>
$this
->
dropdownOptions
,
));
return
ob_get_clean
();
}
}
form/TbFormInputElement.php
0 → 100644
View file @
da78e227
<?php
/**
* TbFormButtonElement class file.
* @author Christoffer Niska <ChristofferNiska@gmail.com>
* @copyright Copyright © Christoffer Niska 2012-
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @package bootstrap.form
* @since 2.0.0
*/
/**
* Bootstrap form builder input element.
*/
class
TbFormInputElement
extends
CFormInputElement
{
/**
* @var array the data for list inputs.
*/
public
$data
;
/**
* @var array additional HTML options to be rendered in the input tag.
*/
public
$htmlOptions
=
array
();
/**
* Renders everything for this input.
* @return string the complete rendering result for this input, including label, input field, hint, and error.
*/
public
function
render
()
{
$form
=
$this
->
getParent
();
return
$form
->
getActiveFormWidget
()
->
inputRow
(
$this
->
type
,
$form
->
getModel
(),
$this
->
name
,
$this
->
data
,
$this
->
htmlOptions
);
}
}
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