Change Which Element Gets Error Class After Validation

Hi everyone,

In my forms instead of:




<div>

<label>

<input>

...

</div>

I use:


<li>

<label>

<div>

<input>

...

</div>

</li>

When there’s a validation error, the error class is added to <div> and the label remains unaltered. What is a neat way to make the label red too? I figure it can be done by changing the validation algorithm to add the error class to <li> instead of <div> and then altering styles accordingly.

Hi my friend

If I understood you want to make a style for label when error occurs

According to

http://www.yiiframework.com/doc/api/1.1/CModel#hasErrors-detail

you could check if error exists by


$model->hasErrors('your_attribute')

or for general error you can use


$model->hasErrors()

So


if ($model->hasErrors('your_attribute')) {

echo '<label style="color:red">';

} else {

echo '<label>';

}



CActiveForm::$clientOptions




<?php $form=$this->beginWidget('CActiveForm', array(

	'clientOptions'=>array(

		'inputContainer'=>'li',

	),

)) ?>



Thanks! The trick with inputContainer worked. I had to alter styles a bit and now in case of client validation error <li> receives the error class and the label becomes red.