Arun Kumar Mudraboyina
Arun Kumar Mudraboyina

Reputation: 779

MTextBox setFocus() not showing the focus on textfield on view load, MGWT

I built an app with gwt,mgwt and gwtphonegap. One of my view having few text fields, I have a requirement that I need to set the default focus on my first field when I visited that view. For this ,

 firstInputField = new MTextBox();
 firstInputField.setFocus(true);

//I'm not calling setFocus() on remaining fields. But my firstInputField not having focus when view is loaded. If there are any straight or alternative ways to do it,please provide me.

thanks in advance,

Arun Kumar.

Upvotes: 1

Views: 141

Answers (1)

Thomas Meyer
Thomas Meyer

Reputation: 53

The Box should be added to the DOM, if you only create a box, without any context to the Browser HTML, it can not handle the focus.

Add the Box in your view and set your Focus, if it is not working, try to wrap the setFocus in a Scheduled Command:

    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                @Override
                public void execute()
                {
                    firstInputField.setFocus(true);
                }
            });

The ScheduledCommand will be fired, after the renderloop is done, and all html elements are ready, and a focus can be set.

Upvotes: 1

Related Questions