PDA

View Full Version : How to put the focus on textfield.



whalethewise
28 Nov 2011, 1:32 PM
Hi,

Is there a simple way to put initial focus on form's textfield?
Like
{
xtype: 'textfield',
id: 'folderName',
name: 'folderName',
fieldLabel: 'name',
labelAlign: 'right',
allowBlank: false,
focus: true,
}

tobiu
28 Nov 2011, 2:19 PM
according to the api docs, there is no focus config you can set.

so, i would add an afterrender listener on the formpanel (if necessary with a little delay) or on the textfield itself and call focus().

like:


listeners: {
afterrender: function(field) { // field = form, depending on where you add the listener
field.focus();
}
}

el_chief
28 Nov 2011, 11:51 PM
if it's a window

defaultFocus:'form_field_name'

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.window.Window-cfg-defaultFocus