How To Apply Error And Success Class For Validated Cjuiautocomplete Field?

Yii uses CSS classes "error" and "success" for highlighting validated fields. Fields which passed validation successfully are highlighted with green color, whereas failed fields - with red. All works fine with standard fields, but I have a problem with CJuiAutoComplete widget.

Fields created by CJuiAutoComplete are not highlighted anyhow. I’m able to add either “error” or “success” CSS class into the CJuiAutoComplete’s “htmlOptions” (and it takes the effect), but I need this to work in the same dynamic manner, as it works for other fields.

How to setup CJuiAutoComplete widget to show appropriate colors for validation status (including validation via AJAX, which certainly involves some javascript part)?

Here is an example of the code:

// this renders lookup field with a constant style, validation independently

  	$this->widget('zii.widgets.jui.CJuiAutoComplete', array(

        'source' => $this->createUrl('price/lookup/shop/'),

        'name' => 'Price[shop_lookup]',

        'id' => 'Price_shop_lookup',

        'value' => $model->getShop_lookup(),



          'select' => 'js:function(event, ui){ /**/ }'



          'size' => 45,

          'maxlength' => 45,

          // 'class' => 'error' - this will color the field in red constantly



// this renders text field with "Price_shop_id" ID in dynamically changing styles according to validation

    echo $form->textField($model,'shop_id',array('size'=>20,'maxlength'=>20));

P.S. After some investigation I found out that the problem arises from the following lines 96-99 of jquery.yiiactiveform.js:

$.fn.yiiactiveform.validate($form, function (data) {

	var hasError = false;

	$.each(settings.attributes, function () {

Here “settings.attributes” contains a listing of persistent fields which are stored in DB. But my lookup fields are virtual (defined as variables in models, and added into “rules” array of the model). So the question is how to add virtual fields into activeform’s attributes? Also it seems important to somehow “tell” to CModel’s validate method (at server-side) to validate ALL attributes mentioned in “rules” array, not only those stored in DB.

Thanks in advance.

The answer is found. Validation is performed only for those attributes from “rules” which have a corresponding call to $form->error method. You can find that form’s attributes are filled in on the last line of CActiveForm::error method.

Seems very unintuitive, concealed, and misleading. I couldn’t find any mention about this in docs, not to say that such design is highly questionable imho.