Yii Framework Forum: No star sign - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

No star sign Rate Topic: -----

#1 User is offline   penkomitev 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 12-February 09

Posted 05 March 2009 - 10:43 AM

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.

Attached File(s)


0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,902
  • Joined: 04-October 08
  • Location:DC, USA

Posted 05 March 2009 - 10:51 AM

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.
0

#3 User is offline   penkomitev 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 12-February 09

Posted 05 March 2009 - 11:30 AM

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.
0

#4 User is offline   donnut 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 10
  • Location:Amsterdam area

Posted 15 February 2010 - 05:26 AM

View Postqiang, on 05 March 2009 - 10:51 AM, said:

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.


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!
0

#5 User is offline   marianzburlea 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 03-June 12
  • Location:London

Posted 18 September 2012 - 06:01 AM

You can also use the afterRequiredLabel, see example below:


	<div class="grid_1 alpha">
		<?php
                CHtml::$afterRequiredLabel = '';
		echo CHtml::activeLabelEx($model,'username');
		?>
	</div>

Company profile: http://smartyii.co.uk
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users