No star sign

Hi guys! I noticed the following:

I have two models - > users and userPersons. The first one responds for the table users, which has standard fields like email, password.

In the second model I have fields specific for the Persons type of registration. I am using the following type to validate EMAIL and PASSWORD:



	public function rules()


	{


return array(


		    array('EMAIL, PASSWORD, PASSWORD_REPEAT', 'required', 'on'=>'create'), 


   			array('PASSWORD','length','max'=>32),


   			array('EMAIL','length','max'=>30),


   			array('EMAIL', 'unique', 'on'=>'create'),


   			array('PASSWORD_REPEAT','length','max'=>32),


   			array('PASSWORD', 'compare', 'compareAttribute'=>'PASSWORD_REPEAT', 'on'=>'create'),


		);





	}


Then, in userPersons controller, I am creating a new instance of the users model. Actually, here is a part of my manipulations there:






		$users->attributes = $_POST['users'];


		$users->USER_ID                 =     $UserID;


		$users->PASSWORD_REPEAT         =     $_POST['users']['PASSWORD_REPEAT'];





		$users->TYPE                    =     "2";





		$userpersons->attributes = $_POST['userPersons'];


		$userpersons->USER_ID  	        = $UserID;





		$result1 = $users->validate("create");


		$result2 = $userpersons->validate("create");





		if($result1 && $result2)


As you see, I implemented your advise in my previous question, why nothing is changed when I use validate and you told me to specify a name after the 'on'=> and then to pass that name as an argument of the validate function.

At present, the validation works after I click the button "Create". I mean that Yii validates properly and requires these fields to have non-zero value and implements the other rules as well, but doesn't show a star, which shows that the fields is mandatory. As I said, it still performs proper validation when I click the Create button, but at the very first start, immediately after you load the form, you are not informed that these fields are required.

Refer to the attachment if you haven't completely understood my post.

I am just looking for your advice whether this is a bug and I have to create a ticket or not.

Thanks.

Displaying the star sign is a big tricky when you use scenario (the 'on' parameter). Basically, you need to set CHtml::$scenario='create' before the form.

Ok, Qiang, this was the issue and actually, in my view, it doesn't need any further discussion as the approach is very simple and everybody would add it to their code, instead of the case where you automate it somehow and then both users and you think of workarounds when something gets wrong.

Thanks.

Hi,

I’m having the same issue, the mandatory-star isn’t showing for fields that are associated with scenario’s. However,

I’ve 7 scenario’s. Is there a solution for version 1.1?

Thanks for creating Yii!

You can also use the afterRequiredLabel, see example below:


	<div class="grid_1 alpha">

		<?php

                CHtml::$afterRequiredLabel = '';

		echo CHtml::activeLabelEx($model,'username');

		?>

	</div>