Yii Framework Forum: Focus First Element In Form - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Focus First Element In Form focus first element in form Rate Topic: -----

#1 User is offline   Sivanthi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 14-February 13
  • Location:Nagercoil, Kanya Kumari, Tamilnadu. India

Posted 15 March 2013 - 05:23 AM

$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,
		
)); 

1

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 16 March 2013 - 03:54 PM

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'

Find more about me.... btw. Do you know your WAN IP?
4

#3 User is offline   Sivanthi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 14-February 13
  • Location:Nagercoil, Kanya Kumari, Tamilnadu. India

Posted 18 March 2013 - 12:32 AM

View PostMaurizio Domba, on 16 March 2013 - 03:54 PM, said:

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.
0

#4 User is offline   raj_y 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 11-July 14

Posted 08 August 2014 - 12:48 AM

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;
});

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users