suggestion for activeLabel

Is it possible to activeLabel automaticaly put a * in required fields?

It would be cool if the string to show (default to '*') and position to show (default to 'before' the label) could be configurable using the htmloptions array.

The fact is that it is difficult for activeLabel to know if an attribute is required or not.

Hi,

for this purpose i extended activeLabel:



public static function activeLabel($model,$attribute,$htmlOptions=array()){


		foreach($model->rules() as $rule){


			if('required'==$rule[1]){


				if(false!==strpos($rule[0], $attribute)){


					if(isset($htmlOptions['class'])){


						$htmlOptions['class'].=' '.self::$requiredCss;


					}


					else{


						$htmlOptions['class']=self::$requiredCss;


					}


					break;


				}


			}


		}


		return parent::activeLabel($model,$attribute,$htmlOptions);


	}


Greetins from Germany

me23

Good job!

I was really thinking in using the model rules.

Your implementation could be incorporated in the framework.