Skip to main content

Posts

Showing posts from July, 2012

GWT: Emulate tab on Enter

Sometimes users expect text boxes to move focus on to the next element after pressing Enter, similar to most spreadsheets. If you are using GWT and jQuery, here is a little snippet to help you along:



publicclassAutoTabbedTextBoxextendsTextBoximplements KeyUpHandler { public AutoTabbedTextBox() { super();         addKeyUpHandler(this);     }
@Override publicvoid onKeyUp(KeyUpEvent event) { // emulate tab on key if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER)             focusNext(event.getNativeEvent());     }
publicnativevoid focusNext(NativeEvent event)/*-{ var inputs = $wnd.$(':input:visible');             inputs.eq(inputs.index(event.target) + 1).focus();     }-*/; }