Highlighting Several Errors After Ajax Validation

I have a form for a model, which contains some related fields. When one field is changed, some other ones are also validated and can contain errors. AJAX validation is enabled.

Currently the only one error is shown - the error (if any) for the field which was edited right now. This looks like an algorithm coded by design - in fact the file jquery.yiiactiveform.js contains the following code in validate callback:

$.each(settings.attributes, function ()


  if (this.status === 2 || this.status === 3)


    hasError = $.fn.yiiactiveform.updateInput(this, data, $form) || hasError;



So, this.status is always 1 ("validated") for all attributes except for the one that has been changed most recently, and thus updateInput is skipped for all other fields.

As a consequence, if, for example, you change the field "name", and ajax validation responce contains the following data:

{"alias":["Your alias is incorrect!"]}

it does not highlight the "alias" field and does not show its error message.

The question is: is there a way to tell Yii to highlight validation errors on all fields?

Dear Friend

You can declare afterValidateAttribute method in clientOptions in the following way.

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





	    'afterValidateAttribute'=>'js:function(form, attribute, data, hasError){

			var settings=form.data("settings");

			var attributes=settings.attributes;


				$.fn.yiiactiveform.updateInput(attribute,data, form);




)); ?>

After each attribute is validated, this script updates the error fields with latest json object received from the server.

It will not work when we set enableClientValidation as true and the validadtor has clientside validation option.

I hope this is what you expect.