Commit 491b26b9 by Crisu83

added input addon support (fixes #23) and moved captchaOptions last

parent 5ccd3444
......@@ -6,6 +6,7 @@
<w>navbar</w>
<w>scrollspy</w>
<w>tabbable</w>
<w>uneditable</w>
<w>unstyled</w>
</words>
</dictionary>
......
......@@ -15,6 +15,8 @@ class TestForm extends CFormModel
public $fileField;
public $uneditable;
public $disabled;
public $prepend;
public $append;
public $disabledCheckbox;
public $captcha;
......@@ -30,6 +32,8 @@ class TestForm extends CFormModel
'fileField'=>'File input',
'uneditable'=>'Uneditable input',
'disabled'=>'Disabled input',
'prepend'=>'Prepend text',
'append'=>'Append text',
'disabledCheckbox'=>'Disabled checkbox',
);
}
......
......@@ -76,6 +76,7 @@
array(
'class'=>'bootstrap.widgets.BootMenu',
'items'=>array(
array('label'=>'Bootstrap Docs', 'url'=>'http://twitter.github.com/bootstrap', 'linkOptions'=>array('target'=>'_blank')),
array('label'=>'Fork me on Bitbucket', 'url'=>'http://www.bitbucket.org/Crisu83/yii-bootstrap', 'linkOptions'=>array('target'=>'_blank')),
array('label'=>'Follow me on Twitter', 'url'=>'http://www.twitter.com/Crisu83', 'linkOptions'=>array('target'=>'_blank')),
),
......
......@@ -724,6 +724,8 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php echo $form->textAreaRow($model, 'textarea', array('class'=>'span8', 'rows'=>5)); ?>
<?php echo $form->uneditableRow($model, 'uneditable'); ?>
<?php echo $form->textFieldRow($model, 'disabled', array('disabled'=>true)); ?>
<?php echo $form->textFieldRow($model, 'prepend', array('prepend'=>'@', 'hint'=>'Coming in version 0.9.10')); ?>
<?php echo $form->textFieldRow($model, 'append', array('append'=>'.00', 'hint'=>'Coming in version 0.9.10')); ?>
<?php echo $form->checkBoxRow($model, 'disabledCheckbox', array('disabled'=>true)); ?>
<?php echo $form->checkBoxListInlineRow($model, 'inlineCheckboxes', array('1', '2', '3')); ?>
<?php echo $form->checkBoxListRow($model, 'checkboxes', array(
......@@ -811,6 +813,8 @@ Yii::app()->user->setFlash('error', '<strong>Oh snap!</strong> Change a few thin
<?php echo \$form->textAreaRow(\$model, 'textarea', array('class'=>'span8', 'rows'=>5)); ?>
<?php echo \$form->uneditableRow(\$model, 'uneditable'); ?>
<?php echo \$form->textFieldRow(\$model, 'disabled', array('disabled'=>true)); ?>
<?php echo \$form->textFieldRow(\$model, 'prepend', array('prepend'=>'@', 'hint'=>'Coming in version 0.9.10')); ?>
<?php echo \$form->textFieldRow(\$model, 'append', array('append'=>'.00', 'hint'=>'Coming in version 0.9.10')); ?>
<?php echo \$form->checkBoxRow(\$model, 'disabledCheckbox', array('disabled'=>true)); ?>
<?php echo \$form->checkBoxListInlineRow(\$model, 'inlineCheckboxes', array('1', '2', '3')); ?>
<?php echo \$form->checkBoxListRow(\$model, 'checkboxes', array(
......
......@@ -196,12 +196,12 @@ class BootActiveForm extends CActiveForm
* Renders a captcha row.
* @param CModel $model the data model
* @param string $attribute the attribute
* @param array $captchaOptions the captcha options
* @param array $htmlOptions additional HTML attributes
* @param array $captchaOptions the captcha options
* @return string the generated row
* @since 0.9.3
*/
public function captchaRow($model, $attribute, $captchaOptions = array(), $htmlOptions = array())
public function captchaRow($model, $attribute, $htmlOptions = array(), $captchaOptions = array())
{
return $this->inputRow(BootInput::TYPE_CAPTCHA, $model, $attribute, $captchaOptions, $htmlOptions);
}
......
......@@ -53,14 +53,23 @@ abstract class BootInput extends CInputWidget
*/
public function init()
{
if ($this->form === null)
if (!isset($this->form))
throw new CException(__CLASS__.': Failed to initialize widget! Form is not set.');
if ($this->model === null)
if (!isset($this->model))
throw new CException(__CLASS__.': Failed to initialize widget! Model is not set.');
if ($this->type === null)
if (!isset($this->type))
throw new CException(__CLASS__.': Failed to initialize widget! Input type is not set.');
if ($this->type === self::TYPE_UNEDITABLE)
{
$cssClass = 'uneditable-input';
if (isset($this->htmlOptions['class']))
$this->htmlOptions['class'] .= ' '.$cssClass;
else
$this->htmlOptions['class'] = $cssClass;
}
}
/**
......@@ -120,12 +129,6 @@ abstract class BootInput extends CInputWidget
break;
case self::TYPE_UNEDITABLE:
$cssClass = 'uneditable-input';
if (isset($this->htmlOptions['class']))
$this->htmlOptions['class'] .= ' '.$cssClass;
else
$this->htmlOptions['class'] = $cssClass;
$this->uneditableField();
break;
......@@ -135,27 +138,86 @@ abstract class BootInput extends CInputWidget
}
/**
* Returns the error text for the input.
* Returns the label for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the error text
* @return string the label
*/
protected function getError($htmlOptions = array())
protected function getLabel($htmlOptions = array())
{
return $this->form->error($this->model, $this->attribute, $htmlOptions);
if ($this->label !== false && !in_array($this->type, array('checkbox', 'radio')) && $this->hasModel())
return $this->form->labelEx($this->model, $this->attribute, $htmlOptions);
else if ($this->label !== null)
return $this->label;
else
return '';
}
/**
* Returns the container CSS class for the input.
* @return string the CSS class.
*/
protected function getContainerCssClass()
protected function getPrepend($htmlOptions = array())
{
if ($this->model->hasErrors($this->attribute))
return CHtml::$errorCss;
if ($this->hasAddOn())
{
$cssClass = 'add-on';
if (isset($htmlOptions['class']))
$htmlOptions['class'] .= ' '.$cssClass;
else
$htmlOptions['class'] = $cssClass;
$cssClass = $this->getInputContainerCssClass();
ob_start();
echo '<div class="'.$cssClass.'">';
if (isset($this->htmlOptions['prepend']))
echo CHtml::tag('span', $htmlOptions, $this->htmlOptions['prepend']);
return ob_get_clean();
}
else
return '';
}
protected function getAppend($htmlOptions = array())
{
if ($this->hasAddOn())
{
$cssClass = 'add-on';
if (isset($htmlOptions['class']))
$htmlOptions['class'] .= ' '.$cssClass;
else
$htmlOptions['class'] = $cssClass;
ob_start();
if (isset($this->htmlOptions['append']))
echo CHtml::tag('span', $htmlOptions, $this->htmlOptions['append']);
echo '</div>';
return ob_get_clean();
}
else
return '';
}
protected function getInputContainerCssClass()
{
if (isset($this->htmlOptions['prepend']))
return 'input-prepend';
else if (isset($this->htmlOptions['append']))
return 'input-append';
else
return '';
}
protected function hasAddOn()
{
return isset($this->htmlOptions['prepend']) || isset($this->htmlOptions['append']);
}
/**
* Returns the error text for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the error text
*/
protected function getError($htmlOptions = array())
{
return $this->form->error($this->model, $this->attribute, $htmlOptions);
}
/**
* Returns the hint text for the input.
* @return string the hint text
......@@ -173,16 +235,13 @@ abstract class BootInput extends CInputWidget
}
/**
* Returns the label for the input.
* @param array $htmlOptions additional HTML attributes
* @return string the label
* Returns the container CSS class for the input.
* @return string the CSS class.
*/
protected function getLabel($htmlOptions = array())
protected function getContainerCssClass()
{
if ($this->label !== false && !in_array($this->type, array('checkbox', 'radio')) && $this->hasModel())
return $this->form->labelEx($this->model, $this->attribute, $htmlOptions);
else if ($this->label !== null)
return $this->label;
if ($this->model->hasErrors($this->attribute))
return CHtml::$errorCss;
else
return '';
}
......
......@@ -20,8 +20,7 @@ class BootInputHorizontal extends BootInput
*/
public function run()
{
$cssClass = $this->getContainerCssClass();
echo CHtml::openTag('div', array('class'=>'control-group '.$cssClass));
echo CHtml::openTag('div', array('class'=>'control-group '.$this->getContainerCssClass()));
parent::run();
echo '</div>';
}
......@@ -33,7 +32,12 @@ class BootInputHorizontal extends BootInput
*/
protected function getLabel($htmlOptions = array())
{
$htmlOptions['class'] = 'control-label';
$cssClass = 'control-label';
if (isset($htmlOptions['class']))
$htmlOptions['class'] .= ' '.$cssClass;
else
$htmlOptions['class'] = $cssClass;
return parent::getLabel($htmlOptions);
}
......@@ -57,7 +61,8 @@ class BootInputHorizontal extends BootInput
*/
protected function checkBoxList()
{
echo $this->getLabel().'<div class="controls">';
echo $this->getLabel();
echo '<div class="controls">';
echo $this->form->checkBoxList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -79,7 +84,8 @@ class BootInputHorizontal extends BootInput
*/
protected function dropDownList()
{
echo $this->getLabel().'<div class="controls">';
echo $this->getLabel();
echo '<div class="controls">';
echo $this->form->dropDownList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -91,7 +97,8 @@ class BootInputHorizontal extends BootInput
*/
protected function fileField()
{
echo $this->getLabel().'<div class="controls">';
echo $this->getLabel();
echo '<div class="controls">';
echo $this->form->fileField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -103,7 +110,8 @@ class BootInputHorizontal extends BootInput
*/
protected function passwordField()
{
echo $this->getLabel().'<div class="controls">';
echo $this->getLabel();
echo '<div class="controls">';
echo $this->form->passwordField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -129,7 +137,8 @@ class BootInputHorizontal extends BootInput
*/
protected function radioButtonList()
{
echo $this->getLabel().'<div class="controls">';
echo $this->getLabel();
echo '<div class="controls">';
echo $this->form->radioButtonList($this->model, $this->attribute, $this->data, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -151,7 +160,8 @@ class BootInputHorizontal extends BootInput
*/
protected function textArea()
{
echo $this->getLabel().'<div class="controls">';
echo $this->getLabel();
echo '<div class="controls">';
echo $this->form->textArea($this->model, $this->attribute, $this->htmlOptions);
echo $this->getError().$this->getHint();
echo '</div>';
......@@ -163,8 +173,11 @@ class BootInputHorizontal extends BootInput
*/
protected function textField()
{
echo $this->getLabel().'<div class="controls">';
echo $this->getLabel();
echo '<div class="controls">';
echo $this->getPrepend();
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getAppend();
echo $this->getError().$this->getHint();
echo '</div>';
}
......@@ -175,7 +188,8 @@ class BootInputHorizontal extends BootInput
*/
protected function captcha()
{
echo $this->getLabel().'<div class="controls"><div class="captcha">';
echo $this->getLabel();
echo '<div class="controls"><div class="captcha">';
echo '<div class="widget">'.$this->widget('CCaptcha', $this->data, true).'</div>';
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getError().$this->getHint();
......@@ -188,7 +202,8 @@ class BootInputHorizontal extends BootInput
*/
protected function uneditableField()
{
echo $this->getLabel().'<div class="controls">';
echo $this->getLabel();
echo '<div class="controls">';
echo CHtml::tag('span', $this->htmlOptions, $this->model->{$this->attribute});
echo $this->getError().$this->getHint();
echo '</div>';
......
......@@ -147,7 +147,9 @@ class BootInputVertical extends BootInput
protected function textField()
{
echo $this->getLabel();
echo $this->getPrepend();
echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
echo $this->getAppend();
echo $this->getError().$this->getHint();
}
......
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