5

I am working with Gxt. I need to set focus to the first enabled field on the page. But I have a lot of pages and I want to centralize that behaviour. There is a lack of documentation in Gxt so I wonder if somebody has met such a problem and can help me.

Now it goes like that in each component's class

protected void resetFocus() {
    combobox.focus();
}

@Override
public void show() {
    super.show();
    resetFocus();
}

I have found com.extjs.gxt.ui.client.aria.FocusManager but is absolutely unclear how can I use it. Or maybe It is also possible to get chain of fields as they go on the component according to the focus. And I can move resetFocus method to the parent class.

Smth like that

protected void resetFocus() {
    *getFocusChain().get(0).focus();*
}
Zalivaka
  • 763
  • 2
  • 13
  • 20
  • 1
    Maybe you can show us your code? It doesn't make people want to help with your problem when you call it a trivial task, it makes you seem lazy in the research part of the problem. – Woot4Moo Nov 03 '10 at 14:27
  • Thanks, you are right! I realized that my post shows me not from a best side. I will rewrite it. – Zalivaka Nov 03 '10 at 18:18
  • rewritten, open for critic and filling need of help. – Zalivaka Nov 03 '10 at 18:32

2 Answers2

3

Based on the last response, I got this to work in a GXT3 window by doing the following:

@Override
public void show() {
    super.show();
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
        @Override
        public void execute() {
            field.focus();
        }
    });
}

This way when the window opens, the field has focus and you can begin typing.

2

Focus after render some delay So you have to use Scheduler.get().scheduleDeferred method. Or DeferredCommand on GWT 1.7 or before.

Example of usage:

Scheduler.get().scheduleDeferred(new ScheduledCommand() {

    @Override
    public void execute() {
        widget.focus();
        widget.el().focus();
        widget.getElement().focus();
    }
});
seanf
  • 6,504
  • 3
  • 42
  • 52
Yusuf K.
  • 4,195
  • 1
  • 33
  • 69
  • It isn't helpful at all. I was looking for solution I can implement once and do not copy-paste focus() code. I have made my own focus management system, so the question is no more actual. – Zalivaka Apr 13 '11 at 14:23
  • Why don't you share your solution here. Maybe your solution will help other people. – Yusuf K. Apr 19 '11 at 12:08
  • 1
    At least it worked for me. I was using scheduleFinally which doesn't work, scheduleDeferred did the trick. I used only someTextField.focus(), in GXT 3 it seems to be enough. – PhiLho Feb 29 '12 at 10:12