Nasty colon and asterisk problem! :)

Hi there,

Got a few questions about labels for fields in standard application/view in Yii:

One. Why there is no colon after label text for each label attribute generated with using standard view? Does English doesn’t need them there? Have to write my own function for workaround this problem.

Two. Why there isn’t easy way to add colon after field, why solution:


echo($form->labelNA($model, 'login').':');

isn’t working like supposed - i.e. colon lands in a new line, proceeding field? Have to write my own function for workaround this problem! :]

Three. Finally, if setting $htmlOption[‘required’] to true and passing it is generating asterisk no matter, if corresponding field is required or not, then why doesn’t it work the other way - i.e. why doesn’t this function is forced not to generate asterisk, no matter, if field or isn’t reqired? Have to write my own function for workaround this problem! :}

Cheers!

  1. Because in some cases such as [x] checkbox label we don’t need it.

  2. Just check CSS. Label tag should not be put to new line if no CSS is forcing it.

  3. Use activeLabel instead of activeLabelEx to avoid asterisk.

I can’t use label I will get rid of asterisk, but won’t get my colon. And if I use:


$form->label($model, 'name').':';

I got in HTML code generated and sent to browser (page source) something like that:


<label for="Users_name">Name</label>:

Colon is directly after label ending tag and I wasn’t aware that styles can force breaking to a new line in this situation (when something is touching directly, not being extracted from rest of flow with div or span) therefore I didn’t know that this is CSS-related problem. Sorry. But on the other hand, I lack a lot of styling knowledge.

There are a few cases when we don’t need the colon so it’s more convenient to code when we don’t need:

I made the following changes in the framework:

Add a parameter $suffix=’:’ to the following functions in CActiveForm.php:




	public function label($model,$attribute,$htmlOptions=array(),$suffix=':')

	{

		return CHtml::activeLabel($model,$attribute,$htmlOptions,$suffix);

	}

	...

	public function labelEx($model,$attribute,$htmlOptions=array(),$suffix=':')

	{

		return CHtml::activeLabelEx($model,$attribute,$htmlOptions,$suffix);

	}



Add this parameter to the respective functions in CHtml.php:




	public static function activeLabel($model,$attribute,$htmlOptions=array(),$suffix=':')

	...

		return self::label($label.$suffix,$for,$htmlOptions);

	...

	public static function activeLabelEx($model,$attribute,$htmlOptions=array(),$suffix=':')

	...

	return self::activeLabel($model,$realAttribute,$htmlOptions,$suffix);

	...



When this is done, every label will be rendered with colon at the end. To disable the colon, call the respective function with empty string




<div class="row rememberMe">

	<?php echo $form->checkBox($model,'rememberMe'); ?>

	<?php echo $form->label($model,'rememberMe',array(),''); ?>

	<?php echo $form->error($model,'rememberMe'); ?>

</div>