Focus First Element In Form


$form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(

	'id'=>'registration-register-form',

	'htmlOptions'=>array('class'=>'well'),

	'enableAjaxValidation'=>true,

	'focus'=>array($model,'columname to focus'),

	'enableClientValidation'=>true,

		

)); 

By using


'focus'=>array($model,'columname to focus')

you need to add the right columnname for every form… a more general selector could be used here, like those suggested on the focus documentation - http://www.yiiframew…rm#focus-detail

To focus first input element of type text:


'focus'=>'input[type="text"]:first' 

To focus first visible and enabled input element


'focus'=>'input:visible:enabled:first' 

To focus first empty input


'focus'=>'input:text[value=""]:first'

Thanks a lot for your information.

In advanced search this is not the case because by default form is hidden(display : none) in advanced search and field is focused, when we click advanced search link to show form (display :block) the field focus is gone.

so I tried this


Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

	$('.search-form').toggle();

	$('input:text:visible:first').focus()

	return false;

});