Commits

Christoffer Niska committed 8d1a916

added support for setting htmlOptions for each form element

Comments (0)

Files changed (4)

widgets/BootActiveForm.php

 	 * @param CModel $model the data model
 	 * @param string $attribute the attribute
 	 * @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, $htmlOptions = array(), $captchaOptions = array())
+	public function captchaRow($model, $attribute, $htmlOptions = array())
 	{
-		return $this->inputRow(BootInput::TYPE_CAPTCHA, $model, $attribute, $captchaOptions, $htmlOptions);
+		return $this->inputRow(BootInput::TYPE_CAPTCHA, $model, $attribute, $htmlOptions);
 	}
 
 	/**

widgets/input/BootInput.php

 
 		if ($this->type === self::TYPE_UNEDITABLE)
 		{
-			$classes = 'uneditable-input';
 			if (isset($this->htmlOptions['class']))
-				$this->htmlOptions['class'] .= ' '.$classes;
+				$this->htmlOptions['class'] .= ' uneditable-input';
 			else
-				$this->htmlOptions['class'] = $classes;
+				$this->htmlOptions['class'] = 'uneditable-input';
 		}
 	}
 
 
 	/**
 	 * Returns the label for the input.
-	 * @param array $htmlOptions additional HTML attributes
 	 * @return string the label
 	 */
-	protected function getLabel($htmlOptions = array())
+	protected function getLabel()
 	{
+		if (isset($this->htmlOptions['labelOptions']))
+		{
+			$htmlOptions = $this->htmlOptions['labelOptions'];
+			unset($this->htmlOptions['labelOptions']);
+		}
+		else
+			$htmlOptions = array();
+
 		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)
 
 	/**
 	 * Returns the prepend element for the input.
-	 * @param array $htmlOptions additional HTML attributes
 	 * @return string the element
 	 */
-	protected function getPrepend($htmlOptions = array())
+	protected function getPrepend()
 	{
 		if ($this->hasAddOn())
 		{
-			$classes = 'add-on';
+			if (isset($this->htmlOptions['prependOptions']))
+			{
+				$htmlOptions = $this->htmlOptions['prependOptions'];
+				unset($this->htmlOptions['prependOptions']);
+			}
+			else
+				$htmlOptions = array();
+
 			if (isset($htmlOptions['class']))
-				$htmlOptions['class'] .= ' '.$classes;
+				$htmlOptions['class'] .= ' add-on';
 			else
-				$htmlOptions['class'] = $classes;
+				$htmlOptions['class'] = 'add-on';
 
 			$classes = $this->getInputContainerCssClass();
 			ob_start();
 			echo '<div class="'.$classes.'">';
 			if (isset($this->htmlOptions['prepend']))
+			{
 				echo CHtml::tag('span', $htmlOptions, $this->htmlOptions['prepend']);
+				unset($this->htmlOptions['prepend']);
+			}
 			return ob_get_clean();
 		}
 		else
 
 	/**
 	 * Returns the append element for the input.
-	 * @param array $htmlOptions additional HTML attributes
 	 * @return string the element
 	 */
-	protected function getAppend($htmlOptions = array())
+	protected function getAppend()
 	{
 		if ($this->hasAddOn())
 		{
-			$classes = 'add-on';
+			if (isset($this->htmlOptions['appendOptions']))
+			{
+				$htmlOptions = $this->htmlOptions['appendOptions'];
+				unset($this->htmlOptions['appendOptions']);
+			}
+			else
+				$htmlOptions = array();
+
 			if (isset($htmlOptions['class']))
-				$htmlOptions['class'] .= ' '.$classes;
+				$htmlOptions['class'] .= ' add-on';
 			else
-				$htmlOptions['class'] = $classes;
+				$htmlOptions['class'] = 'add-on';
 
 			ob_start();
 			if (isset($this->htmlOptions['append']))
+			{
 				echo CHtml::tag('span', $htmlOptions, $this->htmlOptions['append']);
+				unset($this->htmlOptions['append']);
+			}
 			echo '</div>';
 			return ob_get_clean();
 		}
 	}
 
 	/**
+	 * Returns the error text for the input.
+	 * @return string the error text
+	 */
+	protected function getError()
+	{
+		if (isset($this->htmlOptions['errorOptions']))
+		{
+			$htmlOptions = $this->htmlOptions['errorOptions'];
+			unset($this->htmlOptions['errorOptions']);
+		}
+		else
+			$htmlOptions = array();
+
+		return $this->form->error($this->model, $this->attribute, $htmlOptions);
+	}
+
+	/**
+	 * Returns the hint text for the input.
+	 * @return string the hint text
+	 */
+	protected function getHint()
+	{
+		if (isset($this->htmlOptions['hint']))
+		{
+			if (isset($this->htmlOptions['hintOptions']))
+			{
+				$htmlOptions = $this->htmlOptions['hintOptions'];
+				unset($this->htmlOptions['hintOptions']);
+			}
+			else
+				$htmlOptions = array();
+
+			if (isset($htmlOptions['class']))
+				$htmlOptions['class'] .= ' help-block';
+			else
+				$htmlOptions['class'] = 'help-block';
+
+			$hint = $this->htmlOptions['hint'];
+			unset($this->htmlOptions['hint']);
+
+			return CHtml::tag('p', $htmlOptions, $hint);
+		}
+		else
+			return '';
+	}
+
+	/**
+	 * Returns the container CSS class for the input.
+	 * @return string the CSS class
+	 */
+	protected function getContainerCssClass()
+	{
+		$attribute = $this->attribute;
+		return $this->model->hasErrors(CHtml::resolveName($this->model, $attribute)) ? CHtml::$errorCss : '';
+	}
+
+	/**
 	 * Returns the input container CSS classes.
-	 * @return string the classes
+	 * @return string the CSS class
 	 */
 	protected function getInputContainerCssClass()
 	{
 	}
 
 	/**
+	 * Returns the HTML attributes for the CAPTCHA widget.
+	 * @return array the attributes
+	 * @since 0.10.0
+	 */
+	protected function getCaptchaOptions()
+	{
+		if (isset($this->htmlOptions['captchaOptions']))
+		{
+			$htmlOptions = $this->htmlOptions['captchaOptions'];
+			unset($this->htmlOptions['captchaOptions']);
+		}
+		else
+			$htmlOptions = array();
+
+		return $htmlOptions;
+	}
+
+	/**
 	 * Returns whether the input has an add-on (prepend and/or append).
 	 * @return boolean the result
 	 */
 	}
 
 	/**
-	 * 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
-	 */
-	protected function getHint()
-	{
-		if (isset($this->htmlOptions['hint']))
-		{
-			$hint = $this->htmlOptions['hint'];
-			unset($this->htmlOptions['hint']);
-			return '<p class="help-block">'.$hint.'</p>';
-		}
-		else
-			return '';
-	}
-
-	/**
-	 * Returns the container CSS class for the input.
-	 * @return string the CSS class.
-	 */
-	protected function getContainerCssClass()
-	{
-		$attribute = $this->attribute;
-		return $this->model->hasErrors(CHtml::resolveName($this->model, $attribute)) ? CHtml::$errorCss : '';
-	}
-
-	/**
 	 * Renders a checkbox.
 	 * @return string the rendered content
 	 * @abstract

widgets/input/BootInputHorizontal.php

 	 */
 	protected function getLabel($htmlOptions = array())
 	{
-		$classes = 'control-label';
-		if (isset($htmlOptions['class']))
-			$htmlOptions['class'] .= ' '.$classes;
+		if (!isset($this->htmlOptions['labelOptions']))
+			$this->htmlOptions['labelOptions'] = array();
+
+		if (isset($this->htmlOptions['labelOptions']['class']))
+			$this->htmlOptions['labelOptions']['class'] .= ' control-label';
 		else
-			$htmlOptions['class'] = $classes;
-		
-		if(isset($this->htmlOptions['id']))
-			$htmlOptions['for'] = $this->htmlOptions['id'];
+			$this->htmlOptions['labelOptions']['class'] = 'control-label';
 
-		return parent::getLabel($htmlOptions);
+		return parent::getLabel();
 	}
 
 	/**
 	{
 		echo $this->getLabel();
 		echo '<div class="controls"><div class="captcha">';
-		echo '<div class="widget">'.$this->widget('CCaptcha', $this->data, true).'</div>';
+		echo '<div class="widget">'.$this->widget('CCaptcha', $this->getCaptchaOptions(), true).'</div>';
 		echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
 		echo $this->getError().$this->getHint();
 		echo '</div></div>';

widgets/input/BootInputVertical.php

 class BootInputVertical extends BootInput
 {
 	/**
-	 * Renders a CAPTCHA.
-	 * @return string the rendered content
-	 */
-	protected function captcha()
-	{
-		echo $this->getLabel().'<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();
-		echo '</div>';
-	}
-
-	/**
 	 * Renders a checkbox.
 	 * @return string the rendered content
 	 */
 	}
 
 	/**
+	 * Renders a CAPTCHA.
+	 * @return string the rendered content
+	 */
+	protected function captcha()
+	{
+		echo $this->getLabel().'<div class="captcha">';
+		echo '<div class="widget">'.$this->widget('CCaptcha', $this->getCaptchaOptions(), true).'</div>';
+		echo $this->form->textField($this->model, $this->attribute, $this->htmlOptions);
+		echo $this->getError().$this->getHint();
+		echo '</div>';
+	}
+
+	/**
 	 * Renders an uneditable field.
 	 * @return string the rendered content
 	 */