Source for file BootstrapFormWrapper.php
Documentation is available at BootstrapFormWrapper.php
namespace
Adianti \
Wrapper ;
use
Adianti \
Widget \
Wrapper \
AdiantiFormBuilder ;
use
Adianti \
Widget \
Form \
TLabel ;
* Bootstrap form decorator for Adianti Framework
* @author Pablo Dall'Oglio
* @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
* @license http://www.adianti.com.br/framework-license
public function __construct ( TQuickForm $form , $class =
'form-horizontal' )
$this -> decorated =
$form ;
$this -> element -> { 'class' } =
$class ;
$this -> element -> { 'type' } =
'bootstrap' ;
$this -> element -> { 'enctype' } =
"multipart/form-data" ;
$this -> element -> { 'method' } =
'post' ;
$this -> element -> { 'name' } =
$this -> decorated -> getName ( ) ;
$this -> element -> { 'id' } =
$this -> decorated -> getName ( ) ;
$this -> element -> { 'novalidate' } =
'' ;
* Turn on/off client validation
unset
( $this -> element -> { 'novalidate' } ) ;
$this -> element -> { 'novalidate' } =
'' ;
* Redirect calls to decorated object
public function __call ( $method , $parameters )
* Redirect assigns to decorated object
public function __set ( $property , $value )
return $this -> element -> $property =
$value ;
return $this -> decorated -> setName ( $name ) ;
return $this -> decorated -> getName ( ) ;
public function addField ( AdiantiWidgetInterface $field )
return $this -> decorated -> addField ( $field ) ;
public function delField ( AdiantiWidgetInterface $field )
return $this -> decorated -> delField ( $field ) ;
return $this -> decorated -> getField ( $name ) ;
return $this -> decorated -> clear ( ) ;
return $this -> decorated -> setData ( $object ) ;
public function getData ( $class =
'StdClass' )
return $this -> decorated -> getData ( $class ) ;
* Shows the decorated form
$fieldsByRow =
$this -> decorated -> getFieldsByRow ( ) ;
if ( $this -> element -> { 'class' } ==
'form-horizontal' )
$classWidth =
array ( 1 =>
array ( 3 , 9 ) , 2 =>
array ( 2 , 4 ) , 3 =>
array ( 2 , 2 )) ;
$labelClass =
$classWidth [ $fieldsByRow ] [ 0 ] ;
$fieldClass =
$classWidth [ $fieldsByRow ] [ 1 ] ;
$input_rows =
$this -> decorated -> getInputRows ( ) ;
foreach ( $input_rows as $input_row )
$field_label =
$input_row [ 0 ] ;
$required =
$input_row [ 2 ] ;
$original_row =
$input_row [ 3 ] ;
// form vertical doesn't group elements, just change form group grid class
if ( empty ( $this -> currentGroup ) OR ( $fieldCount %
$fieldsByRow ) ==
0 OR ( strpos ( $this -> element -> { 'class' } , 'form-vertical' ) !==
FALSE ) )
// add the field to the container
$this -> currentGroup =
new TElement ( 'div' ) ;
foreach ( $original_row -> getProperties ( ) as $property =>
$value )
$this -> currentGroup -> $property =
$value ;
$this -> currentGroup -> { 'class' } =
'row tformrow form-group' ;
$this -> currentGroup -> { 'class' } .=
( ( strpos ( $this -> element -> { 'class' } , 'form-vertical' ) !==
FALSE ) ?
' col-sm-' .
( 12 /
$fieldsByRow ) :
'' ) ;
$this -> element -> add ( $this -> currentGroup ) ;
$group =
$this -> currentGroup ;
if ( $field_label instanceof
TLabel )
$label -> add ( $field_label ) ;
if ( $this -> element -> { 'class' } ==
'form-inline' )
$label -> { 'style' } =
'padding-left: 3px; font-weight: bold' ;
$label -> { 'style' } =
'font-weight: bold; margin-bottom: 3px' ;
if ( $this -> element -> { 'class' } ==
'form-horizontal' )
$label -> { 'class' } =
'col-sm-' .
$labelClass .
' control-label' ;
$label -> { 'class' } =
' control-label' ;
$group -> { 'style' } =
'display:none' ;
if ( $this -> element -> { 'class' } !==
'form-inline' )
if ( $this -> element -> { 'class' } ==
'form-horizontal' )
$col -> { 'class' } =
'col-sm-' .
$fieldClass .
' fb-field-container' ;
foreach ( $fields as $field )
if ( $this -> element -> { 'class' } ==
'form-inline' )
$label -> { 'style' } .=
';float:left' ;
if ( $this -> decorated -> getActionButtons ( ))
$group -> { 'class' } =
'form-group' ;
if ( $this -> element -> { 'class' } ==
'form-horizontal' )
$col -> { 'class' } =
'col-sm-offset-' .
$labelClass .
' col-sm-' .
$fieldClass ;
foreach ( $this -> decorated -> getActionButtons ( ) as $action )
$this -> element -> add ( $group ) ;
$this -> element -> { 'width' } =
'100%' ;