Commit 377fe8c2 by TTouka

Updated TbActiveForm

parent 56c62171
......@@ -3,11 +3,11 @@
<legend><?php echo CHtml::encode($language); ?> translation</legend>
<?php echo $form->textFieldRow($model, "[{$locale}]textField"); ?>
<?php echo $form->textAreaRow($model, "[{$locale}]textarea", array('class'=>'span8', 'rows'=>8)); ?>
<?php echo $form->textAreaRow($model, "[{$locale}]textarea", array('rows'=>8)); ?>
<?php echo $form->checkBoxListRow($model, "[{$locale}]checkboxes", array(
'Option one is this and that—be sure to include why it\'s great',
'Option two can also be checked and included in form results',
'Option three can—yes, you guessed it—also be checked and included in form results',
), array('hint'=>'<strong>Note:</strong> Labels surround all the options for much larger click areas.')); ?>
</fieldset>
\ No newline at end of file
</fieldset>
......@@ -994,8 +994,8 @@ Yii::app()->clientScript->registerScript('siteIndex', "
'htmlOptions'=>array('class'=>'well'),
)); ?>
<?php echo $form->textFieldRow($model, 'textField', array('class'=>'col-md-3')); ?>
<?php echo $form->passwordFieldRow($model, 'password', array('class'=>'col-md-3')); ?>
<?php echo $form->textFieldRow($model, 'textField'); ?>
<?php echo $form->passwordFieldRow($model, 'password'); ?>
<?php echo $form->checkboxRow($model, 'checkbox'); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'Login')); ?>
......@@ -1009,8 +1009,8 @@ Yii::app()->clientScript->registerScript('siteIndex', "
'htmlOptions'=>array('class'=>'well'),
)); ?>
<?php echo \$form->textFieldRow(\$model, 'textField', array('class'=>'col-md-3')); ?>
<?php echo \$form->passwordFieldRow(\$model, 'password', array('class'=>'col-md-3')); ?>
<?php echo \$form->textFieldRow(\$model, 'textField'); ?>
<?php echo \$form->passwordFieldRow(\$model, 'password'); ?>
<?php echo \$form->checkboxRow(\$model, 'checkbox'); ?>
<?php \$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'Login')); ?>
......@@ -1025,7 +1025,7 @@ Yii::app()->clientScript->registerScript('siteIndex', "
'htmlOptions'=>array('class'=>'well'),
)); ?>
<?php echo $form->textFieldRow($model, 'textField', array('class'=>'input-medium', 'prepend'=>'<i class="icon-search"></i>')); ?>
<?php echo $form->textFieldRow($model, 'textField', array('class'=>'input-medium', 'prepend'=>'<i class="glyphicon glyphicon-search"></i>')); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'Go')); ?>
<?php $this->endWidget(); ?>
......@@ -1039,7 +1039,7 @@ Yii::app()->clientScript->registerScript('siteIndex', "
'htmlOptions'=>array('class'=>'well'),
)); ?>
<?php echo \$form->textFieldRow(\$model, 'textField', array('class'=>'input-medium', 'prepend'=>'<i class=\"icon-search\"></i>')); ?>
<?php echo \$form->textFieldRow(\$model, 'textField', array('class'=>'input-medium', 'prepend'=>'<i class=\"glyphicon glyphicon-search\"></i>')); ?>
<?php \$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'Go')); ?>
<?php \$this->endWidget(); ?>"); ?>
......@@ -1112,9 +1112,11 @@ Yii::app()->clientScript->registerScript('siteIndex', "
</fieldset>
<div class="form-actions">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Submit')); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset', 'label'=>'Reset')); ?>
</div>
</div>
<?php $this->endWidget(); ?>
......@@ -1155,9 +1157,11 @@ Yii::app()->clientScript->registerScript('siteIndex', "
</fieldset>
<div class=\"form-actions\">
<div class=\"form-group\">
<div class=\"col-sm-offset-2 col-sm-10\">
<?php \$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Submit')); ?>
<?php \$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset', 'label'=>'Reset')); ?>
</div>
</div>
<?php \$this->endWidget(); ?>"); ?>
......@@ -1174,9 +1178,11 @@ Yii::app()->clientScript->registerScript('siteIndex', "
'tabs'=>$this->getTabularFormTabs($form, $model),
)); ?>
<div class="form-actions">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Submit')); ?>
<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset', 'label'=>'Reset')); ?>
</div>
</div>
<?php $this->endWidget(); ?>
......@@ -1193,9 +1199,11 @@ Yii::app()->clientScript->registerScript('siteIndex', "
'tabs'=>\$this->getTabularFormTabs(\$form, \$model),
)); ?>
<div class=\"form-actions\">
<div class=\"form-group\">
<div class=\"col-sm-offset-2 col-sm-10\">
<?php \$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Submit')); ?>
<?php \$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset', 'label'=>'Reset')); ?>
</div>
</div>
<?php \$this->endWidget(); ?>"); ?>
......@@ -1220,7 +1228,7 @@ Yii::app()->clientScript->registerScript('siteIndex', "
<legend><?php echo CHtml::encode(\$language); ?> translation</legend>
<?php echo \$form->textFieldRow(\$model, \"[{\$locale}]textField\"); ?>
<?php echo \$form->textAreaRow(\$model, \"[{\$locale}]textarea\", array('class'=>'col-md-8', 'rows'=>8)); ?>
<?php echo \$form->textAreaRow(\$model, \"[{\$locale}]textarea\", array('rows'=>8)); ?>
<?php echo \$form->checkBoxListRow(\$model, \"[{\$locale}]checkboxes\", array(
'Option one is this and that—be sure to include why it\'s great',
'Option two can also be checked and included in form results',
......
......@@ -45,10 +45,17 @@ class TbActiveForm extends CActiveForm
*/
public function init()
{
$formType = '';
if ($this->type === self::TYPE_VERTICAL)
$formType = 'form';
elseif ($this->type === self::TYPE_SEARCH)
$formType = 'form-inline';
else
$formType = 'form-'.$this->type;
if (!isset($this->htmlOptions['class']))
$this->htmlOptions['class'] = 'form-'.$this->type;
$this->htmlOptions['class'] = $formType;
else
$this->htmlOptions['class'] .= ' form-'.$this->type;
$this->htmlOptions['class'] .= ' '.$formType;
if (!isset($this->inlineErrors))
$this->inlineErrors = $this->type === self::TYPE_HORIZONTAL;
......@@ -486,6 +493,13 @@ class TbActiveForm extends CActiveForm
*/
public function inputRow($type, $model, $attribute, $data = null, $htmlOptions = array())
{
if (in_array($type, array(TbInput::TYPE_DROPDOWN, TbInput::TYPE_PASSWORD, TbInput::TYPE_TEXTAREA, TbInput::TYPE_TEXT, TbInput::TYPE_UNEDITABLE)))
{
if (isset($htmlOptions['class']))
$htmlOptions['class'] .= " form-control";
else
$htmlOptions['class'] = "form-control";
}
ob_start();
$this->getOwner()->widget($this->getInputClassName(), array(
'form'=>$this,
......
......@@ -183,6 +183,7 @@ abstract class TbInput extends CInputWidget
*/
public function run()
{
echo '<div class="form-group">';
switch ($this->type)
{
case self::TYPE_CHECKBOX:
......@@ -241,6 +242,7 @@ abstract class TbInput extends CInputWidget
default:
throw new CException(__CLASS__.': Failed to run widget! Type is invalid.');
}
echo '</div>';
}
/**
......@@ -268,9 +270,9 @@ abstract class TbInput extends CInputWidget
$htmlOptions = $this->prependOptions;
if (isset($htmlOptions['class']))
$htmlOptions['class'] .= ' add-on';
$htmlOptions['class'] .= ' input-group-addon';
else
$htmlOptions['class'] = 'add-on';
$htmlOptions['class'] = 'input-group-addon';
ob_start();
echo '<div class="'.$this->getAddonCssClass().'">';
......@@ -294,9 +296,9 @@ abstract class TbInput extends CInputWidget
$htmlOptions = $this->appendOptions;
if (isset($htmlOptions['class']))
$htmlOptions['class'] .= ' add-on';
$htmlOptions['class'] .= ' input-group-addon';
else
$htmlOptions['class'] = 'add-on';
$htmlOptions['class'] = 'input-group-addon';
ob_start();
if (isset($this->appendText))
......@@ -368,10 +370,7 @@ abstract class TbInput extends CInputWidget
protected function getAddonCssClass()
{
$classes = array();
if (isset($this->prependText))
$classes[] = 'input-prepend';
if (isset($this->appendText))
$classes[] = 'input-append';
$classes[] = 'input-group';
return implode(' ', $classes);
}
......
......@@ -32,9 +32,9 @@ class TbInputHorizontal extends TbInput
protected function getLabel()
{
if (isset($this->labelOptions['class']))
$this->labelOptions['class'] .= ' control-label';
$this->labelOptions['class'] .= ' col-sm-2 control-label';
else
$this->labelOptions['class'] = 'control-label';
$this->labelOptions['class'] = 'col-sm-2 control-label';
return parent::getLabel();
}
......@@ -46,7 +46,7 @@ class TbInputHorizontal extends TbInput
protected function checkBox()
{
$attribute = $this->attribute;
echo '<div class="controls">';
echo '<div class="col-sm-offset-2 col-sm-10">';
echo '<label class="checkbox" for="'.$this->getAttributeId($attribute).'">';
echo $this->form->checkBox($this->model, $attribute, $this->htmlOptions).PHP_EOL;
echo $this->model->getAttributeLabel($attribute);
......@@ -61,7 +61,7 @@ class TbInputHorizontal extends TbInput
protected function checkBoxList()
{
echo $this->getLabel();
echo '<div class="controls">';
echo '<div class="col-sm-10">';
echo $this->form->checkBoxList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -84,7 +84,7 @@ class TbInputHorizontal extends TbInput
protected function dropDownList()
{
echo $this->getLabel();
echo '<div class="controls">';
echo '<div class="col-sm-10">';
echo $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -97,7 +97,7 @@ class TbInputHorizontal extends TbInput
protected function fileField()
{
echo $this->getLabel();
echo '<div class="controls">';
echo '<div class="col-sm-10">';
echo $this->form->fileField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -110,7 +110,7 @@ class TbInputHorizontal extends TbInput
protected function passwordField()
{
echo $this->getLabel();
echo '<div class="controls">';
echo '<div class="col-sm-10">';
echo $this->getPrepend();
echo $this->form->passwordField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getAppend();
......@@ -125,7 +125,7 @@ class TbInputHorizontal extends TbInput
protected function radioButton()
{
$attribute = $this->attribute;
echo '<div class="controls">';
echo '<div class="col-sm-offset-2 col-sm-10">';
echo '<label class="radio" for="'.$this->getAttributeId($attribute).'">';
echo $this->form->radioButton($this->model, $attribute, $this->htmlOptions).PHP_EOL;
echo $this->model->getAttributeLabel($attribute);
......@@ -140,7 +140,7 @@ class TbInputHorizontal extends TbInput
protected function radioButtonList()
{
echo $this->getLabel();
echo '<div class="controls">';
echo '<div class="col-sm-10">';
echo $this->form->radioButtonList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -163,7 +163,7 @@ class TbInputHorizontal extends TbInput
protected function textArea()
{
echo $this->getLabel();
echo '<div class="controls">';
echo '<div class="col-sm-10">';
echo $this->form->textArea($this->model, $this->attribute, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -176,7 +176,7 @@ class TbInputHorizontal extends TbInput
protected function textField()
{
echo $this->getLabel();
echo '<div class="controls">';
echo '<div class="col-sm-10">';
echo $this->getPrepend();
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getAppend();
......@@ -191,7 +191,7 @@ class TbInputHorizontal extends TbInput
protected function captcha()
{
echo $this->getLabel();
echo '<div class="controls"><div class="captcha">';
echo '<div class="col-sm-10"><div class="captcha">';
echo '<div class="widget">'.$this->widget('CCaptcha', $this->captchaOptions, true).'</div>';
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getError().$this->getHint();
......@@ -205,7 +205,7 @@ class TbInputHorizontal extends TbInput
protected function uneditableField()
{
echo $this->getLabel();
echo '<div class="controls">';
echo '<div class="col-sm-10">';
echo CHtml::tag('span', $this->htmlOptions, $this->model->{$this->attribute});
echo $this->getError().$this->getHint();
echo '</div>';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment