Labelex Not Getting The Required *

Guys hi changed the text that I need in one of the labels. This field is a required field and now I am not getting the star. Anybody knows a fix


<p class="note">Fields with <span class="required">*</span> are required.</p>

 

	<?php echo $form->errorSummary($model); ?>

	<div class="row">

		<?php echo $form->labelEx($model,'vehicle registration number'); ?>

		<?php echo $form->textField($model,'registration',array('size'=>60,'maxlength'=>128)); ?>

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

	</div>

How do I get the star to be displayed. Basically how do I insert the <span class=“required”>*</span> in <?php echo $form->labelEx($model,‘vehicle registration number’); ?>

You should check CActiveForm::labelEx doc, you’re using it in a wrong way. If you want to change the label’s text, you should do it in the model’s attributeLabels

Oh ya, just realized thanx :slight_smile:

Just my 5 cents:

labelEx works fine on the DEFAULT model’s attributes, but it does not get an attribute (normally the FK) label in the RELATED model.

This means you have to label your FK in all models where it is used. This obviously results in multiple labels in different models for basically the same field.

I don’t want this. I want to label a field in its own model, and never again in any other model.

So, test if the FK is ‘required’ in the default model; but then get its label in its own (related) model. To do this use “activeLabel”.

You can even use the label of another field if required e.g. in the following code I display the label of enterprise_name while I test if enterprise_id is ‘required’ (I do this because I have a dropdownlist of all the names, but the resulting ID is stored in the FK):




<?php

	echo CHtml::activeLabel($model,'relationToEnterpriseModel.enterprise_name', 	array(

		'required' => $model->isAttributeRequired('enterprise_id')		

	));

?>



I have a standard model with the following in attributeLabels:




'arch_sub_status' => 'Status',



It fails and my label is: "Arch Sub Status"

Other labels in the same class I have modified are just fine, so this is a bug <_<

  • Yep - had a space in labelEx.