Focus to field on error in ajax validation

I am using CActive form ajax submission and validation. In the ‘afterValidate’ event I am using the $.ajax function to submit the data. How can I focus to a field that has error on validation. We can set the ‘focus’ option as given here, but it will focus only on page load.

Try this -


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

           'id'=>'Demo',

            'focus'=>'#Demo input:text:empty:first,'

                       . '#Demo input[class=error]:first',

 )); 

The ‘focus’ option will work only on page reload.