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

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


如何防止用户在没有建议的TextArea中放置字符?

我认为SuggestBox检查已放入TextArea的文本,然后显示建议。但是,如何防止不再匹配的字符呢?

最佳答案

如果您真的需要

   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);

08-06 20:27