Yii Framework Forum: Change Which Element Gets Error Class After Validation - Yii Framework Forum

Jump to content

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

Change Which Element Gets Error Class After Validation Rate Topic: -----

#1 User is offline   schtirlizzz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 12-March 13

Posted 25 May 2013 - 02:14 PM

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

#2 User is offline   Kostas Apazidis (KonApaz) 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,377
  • Joined: 21-February 11
  • Location:Greece

Posted 25 May 2013 - 09:38 PM

Hi my friend

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

According to
http://www.yiiframew...asErrors-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>';
}

Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   Tsunami 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 16-February 12

Posted 26 May 2013 - 03:59 AM

CActiveForm::$clientOptions

Quote

inputContainer: string, the jQuery selector for the HTML element containing the input field. During the validation process, CActiveForm will set different CSS class for the container element to indicate the state change. If not set, it means the closest 'div' element that contains the input field.

<?php $form=$this->beginWidget('CActiveForm', array(
	'clientOptions'=>array(
		'inputContainer'=>'li',
	),
)) ?>

1

#4 User is offline   schtirlizzz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 12-March 13

Posted 28 May 2013 - 05:04 AM

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