4

I have trivial window:

   this.window = Ext.widget('window', {
            title: 'Find',
            closeAction: 'hide',
            width: 300,
            layout: 'fit',
            items: form
        });

with trivial form in it

var form = Ext.widget('form', {
    layout: {
        type: 'vbox',
        align: 'stretch'
    },
    border: false,
    bodyPadding: 10,

    items: [
        this.findInput,
    ]
});

which only has one item

    this.findInput = Ext.widget('textfield', {
        name: 'find'
    });

The issue is: how to set focus right after window is shown? I tried to call .focus() method of this.findInput in almost every window event handler with no luck.

Seems like even afterrender is called synchronously before DOM has created all the elements completely.

What have I missed? What event should I bind to to have all the elements rendered and able to accept the focus?

PS: if I call the same .focus() after small interval like 10ms - I get it focused, but it's not a solution

zerkms
  • 249,484
  • 69
  • 436
  • 539
  • See also [Set focus on Extjs textfield](https://stackoverflow.com/questions/6591371/set-focus-on-extjs-textfield) – Vadzim Feb 26 '18 at 14:19

1 Answers1

6

Check out activeItem property - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel-cfg-activeItem

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

sha
  • 17,824
  • 5
  • 63
  • 98
  • Unfortunately it doesn't work with `vbox` layout. At least after adding `activeItem: 0` to both form and window - nothing's changed. And in extjs sources I only see it in `card` layout – zerkms Jun 19 '12 at 02:05
  • Try this one: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.window.Window-cfg-defaultFocus – sha Jun 19 '12 at 02:15
  • Yep, `defaultFocus` is what I was looking for. Put it as an answer please – zerkms Jun 19 '12 at 02:27