How do you go about creating KeyPress filter that would enforce only digits as input开发者_JS百科 in text field. Something like this here:
http://www.smartclient.com/smartgwt/showcase/#form_keypress_filterAs added anoyence is there a way of doing this in uiBinder xml file?
The code to do that is described here.
In your uiBinder file, define your TextBox item.
<g:TextBox uifield='textBox'/>
In your class, you can either add the KeyPressHandler directly, like :
textBox.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
if (!"0123456789".contains(String.valueOf(event.getCharCode()))) {
textBox.cancelKey();
}
}
});
Or you can use the @UiHandler annotation like so:
@UiHandler("testBox")
public void onKeyPress(KeyPressEvent event) {
if (!"0123456789".contains(String.valueOf(event.getCharCode()))) {
textBox.cancelKey();
}
}
精彩评论