防止SuggestBox中的用户输入无效?

时间:2013-03-08 14:00:13

标签: java gwt

SuggestBox接受用户输入并使用GWT在弹出窗口中显示suggestions

SuggestBox suggestBox = new SuggestBox(myData, new TextArea());

如何阻止用户在没有建议的TextArea中添加字符?

我认为SuggestBox会检查已放入TextArea的文字,然后显示建议。但是我怎么能防止那些不再匹配的角色呢?

1 个答案:

答案 0 :(得分:1)

如果你真的需要那个

   TextArea area = new TextArea();
             area.addKeyDownHandler(new KeyDownHandler() {

                @Override
                public void onKeyDown(KeyDownEvent event) {
                    if(event.getNativeKeyCode()==13 ||....){//Add remaining key codes which you dont want.For example i added enter key which keycode is 13.Remove that and add your key codes there. 
                        event.preventDefault();
                 }  
                }
            });

然后

SuggestBox suggestBox = new SuggestBox(myData,area);