[SOLVED] Focus on error

Hi,

Has anybody come up with a solution to focus on the first field on initial page load and then on the first error after validation fails?


<?php

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

            'htmlOptions' => array(

                'enctype' => 'multipart/form-data',

            ),

            'focus'=>'.error:first',

        ));

    ?>

Cheers,

Matt

I think this should work in most cases.




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

            'htmlOptions' => array(

                'enctype' => 'multipart/form-data',

            ),

            'focus'=>($model->hasErrors()) ? '.error:first' : array($model, 'title'),

            'enableClientValidation' => true,

        ));



Cheers,

Matt

hi friends you can use

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

				'id'=&gt;'login-form',


				//'action'=&gt; Yii::app()-&gt;createUrl( '/user/login'),


				'enableClientValidation'=&gt;true,


				'focus'=&gt;array(&#036;model,'username'),


				'clientOptions'=&gt;array(


	                        'validateOnSubmit'=&gt;true,

),

)); ?>

it works fine for me…