Reputation: 2331
i'm using
echo $form->error($model,'username');
to display validation errors for attribute. But by default it uses div tag with custom class to wrap message itself. I want to use another tag and class. How can i change it?
Upvotes: 2
Views: 3254
Reputation: 61
You have two ways of accomplishing your result. You can either use the $errorMessageCssClass property in the definition of the form widget like this:
$form = $this->beginWidget ( 'CActiveForm', array (
'id' => 'test-form',
'enableClientValidation' => true,
'errorMessageCssClass'=>'the error class you want',...........
which will apply to all the elements in your form... OR you can be more specific to an item using:
<?php echo $form->error($model,'password', array('class'=>'your desired class'); ?>
hope it helps
Upvotes: 0
Reputation: 8587
You can change the static errorContainerTag
of CHtml
before you render the errors in your view file:
<?php
CHtml::$errorContainerTag = 'span';
Upvotes: 1
Reputation: 1179
I suppose that you have to override the error()
method of the CActiveForm
class. You can also use the errorMessageCssClass
class property to change the CSS for the error message.
Upvotes: 1