[SOLVED] Change form error CSS class

Hello all. New Yii user here.

Is there a way to change the css class name of form errors? Say from the form model? I'm using the default CSS class (error), but would want to change its name for other form fields depending on the result of a custom validator. Actually what I'm trying to display is not an error message but some kind of help message when a user has entered a correct value in a form field, and I want to display that message differently from the other messages (errors).

I tried reading through the forum and documentation but I could not find anything related. Thanks in advance for any insights on this topic.

To change the class, you could set CHtml::$errorCss='xyz' at the beginning of your view.

Yii doesn't define css class for correct input. You will have to implement it by yourself.

Thanks for the quick reply qiang, but wouldn't that change the CSS class for ALL errors in the form? Is there a way to assign this from a custom field validator in the form model so that only the affected field would have a different css class? Sorry, I'm still trying to wrap my head around all these concepts.

I guess the proper way to do it is as you suggested (implement my own method of defining a css class for correct input), but right now I wouldn’t know how to start doing that (still very much learning the ropes–but I’m growing to like Yii more and more). Figured that for now I’ll just reuse the existing errorMessage for another purpose, if I can  ;D.

Big thanks for creating a very powerful framework, after a short stint with codeigniter I'm learning to appreciate Yii more and more. I was thinking of switching to Kohana for a little project of mine but glad that I found out about Yii just before I took that route.

Yes, setting CHtml::$errorCss would affect the code after the assignment (you could change it back if needed, though).

Because the css class is more related with presentation, it is not very appropriate to put it in either model or validator.

So, yes, you would need to implement this yourself.

Thank you for your appreciation of Yii and welcome!

Quote

Yes, setting CHtml::$errorCss would affect the code after the assignment (you could change it back if needed, though).

Because the css class is more related with presentation, it is not very appropriate to put it in either model or validator.

Yay! Should have realized this one if I had thought harder (slap to forehead). Guess the lateness of the hour is not very conducive to thinking right. I was approaching the problem the wrong way (from the form model when I should be approaching it from the view (another slap to the forehead)).

Thanks qiang!