开发者

GWT KeyPress filter

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_filter

As 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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜