Commits

Sam Stenvall committed 1c04cb9

fixed label association when input has a user-defined id attribute (fixes #72)

  • Participants
  • Parent commits 72a31b8

Comments (0)

Files changed (3)

widgets/input/BootInput.php

 		else
 			return '';
 	}
+	
+	/**
+	 * Returns the id that should be used for the specified attribute
+	 * @param string $attribute the attribute
+	 * @return string the id 
+	 */
+	protected function getAttributeId($attribute) 
+	{
+		return isset($this->htmlOptions['id']) ? $this->htmlOptions['id'] : 
+			CHtml::getIdByName(CHtml::resolveName($this->model, $attribute));
+	}
 
 	/**
 	 * Returns the input container CSS classes.

widgets/input/BootInputHorizontal.php

 			$htmlOptions['class'] .= ' '.$classes;
 		else
 			$htmlOptions['class'] = $classes;
+		
+		if(isset($this->htmlOptions['id']))
+			$htmlOptions['for'] = $this->htmlOptions['id'];
 
 		return parent::getLabel($htmlOptions);
 	}
 	{
 		$attribute = $this->attribute;
 		echo '<div class="controls">';
-		echo '<label class="checkbox" for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $attribute)).'">';
+		echo '<label class="checkbox" for="'.$this->getAttributeId($attribute).'">';
 		echo $this->form->checkBox($this->model, $attribute, $this->htmlOptions).PHP_EOL;
 		echo $this->model->getAttributeLabel($attribute);
 		echo $this->getError().$this->getHint();

widgets/input/BootInputVertical.php

 	protected function checkBox()
 	{
 		$attribute = $this->attribute;
-		echo '<label class="checkbox" for="'.CHtml::getIdByName(CHtml::resolveName($this->model, $attribute)).'">';
+		echo '<label class="checkbox" for="'.$this->getAttributeId($attribute).'">';
 		echo $this->form->checkBox($this->model, $this->attribute, $this->htmlOptions).PHP_EOL;
 		echo $this->model->getAttributeLabel($attribute);
 		echo $this->getError().$this->getHint();