PDA

View Full Version : Widget Focus



thursday
11 Oct 2011, 4:54 AM
I see that Window.setFocusWidget(Widget) is used to receive the focus. It works perfectly fine!.

But how do I set focus to a widget which is added to the non window containers such as ContentPanel
or LayoutContainer?.

The following example does not have default focus. One has to click text field to start editing.

http://www.sencha.com/examples/pages/forms/forms.html

I tried widget.focus(), widget.el().focus() after the component is rendered. But still the focus is not working.

cimballi
11 Oct 2011, 6:26 AM
You should try this in your panel class :
protected void onAttach() {
super.onAttach();


this.mywidget.focus();
}

jadrake75
11 Oct 2011, 12:02 PM
Also put your focus calls in a deferred scheduler. Most browsers will not allow the focus to be achieved until after the event loop is finished.


Scheduler.get().scheduleDeferred( new ScheduledCommand() {
public void execute( ) {
widget.setFocus(true); // assuming GWT widget or component.focus( ); for GXT
}
});

-Jason

thursday
12 Oct 2011, 12:23 AM
Jason's solution worked for me. Thanks Jason!.