RequiredValue

Hi,

since 1.0.10, the required validator accepts ‘requiredValue’ as parameter, and after test, I’ve noticed a strange behaviour : after a successful validation, if the completed form is displayed again, fields with a requiredValue parameter have ‘error’ as class (error summary is empty).

(see attached screenshot)

Here is the code I used :

[size="4"]The Model[/size]




class TestRequiredValue extends CFormModel

{

	public $username;

	public $address;


	public function rules()

	{

		return array(

			array('username', 'required' ,'requiredValue' => 'yii'),

			array('address', 'required'),

		);

	}

}



[size="4"]The View[/size]





<h1>Required Value</h1>

<pre>

	<?php if($postedData != null) echo CVarDumper::dumpAsString($postedData); ?>

</pre>

<div class="yiiForm">


	<?php echo CHtml::beginForm(); ?>

	

	<?php echo CHtml::errorSummary($model); ?>

	

		<div class="simple">

			<?php echo CHtml::activeLabel($model,'username'); ?>

			<?php echo CHtml::activeTextField($model,'username'); ?>

		</div>

		<div class="simple">

			<?php echo CHtml::activeLabel($model,'address'); ?>

			<?php echo CHtml::activeTextField($model,'address'); ?>

		</div>

	

	<div class="action">

		<?php echo CHtml::submitButton('Submit'); ?>

	</div>

	

	<?php echo CHtml::endForm(); ?>


</div><!-- yiiForm -->



The controller action




	public function actionRequiredValue()

	{

		$model=new TestRequiredValue;

		if(isset($_POST['TestRequiredValue']))

		{

			$model->attributes=$_POST['TestRequiredValue'];

			if($model->validate())

			{

				$this->render('requiredValue',array('model'=>$model,

				'postedData'=> $_POST['TestRequiredValue']));

				return;

			}

		}

		$this->render('requiredValue',array('model'=>$model));

	}



I don’t know if it’s a bug or if I’m doing something wrong …

ciao

8)

i think it is a bit bug for requiredValue~

http://code.google.com/p/yii/issues/detail?id=710

ok, thanks for reporting it ;)

8)