开发者

GWT KeyPress filter

开发者 https://www.devze.com 2023-03-10 15:50 出处:网络
How do you go about creating KeyPress filter that would enforce only digits as input开发者_JS百科 in text field. Something like this here:

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

精彩评论

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