PDA

View Full Version : How to set the default focus for a control on a view



cswsteve
15 Dec 2012, 11:26 AM
I have a view with 10 text boxes but when I first open the view none of the text boxes have the focus. After pressing the Tab key once or twice then the first text box gets the focus and I can control the rest of the tabbing order by using the tabIndex.

How can I get the first text box to have the cursor flashing in it ready for the user to start typing data?

Thanks

slemmon
15 Dec 2012, 2:13 PM
If the component you're working with is a window you can use:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.window.Window-cfg-defaultFocus

Otherwise you might set a listener for your component's boxready event. Something like:



listeners: {
boxready: function (cp) {
cp.down('field').focus(); // or any other query/selector that makes sense for your layout
}
}

cswsteve
15 Dec 2012, 2:23 PM
I tried that but it didn't work until I also set the autoShow to True. Here are the steps if anyone else wants to know how to do this.


Set the itemId of the component you want to set the focus to. (ex: txtUserName)
Select the Window and set autoShow to True.
Then set defaultFocus to the itemId of the component.