简体   繁体   English

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

[英]Prevent invalid user input in SuggestBox?

I have SuggestBox taking user input and displaying suggestions in a popup using GWT. 我有SuggestBox接受用户输入并使用GWT在弹出窗口中显示suggestions

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

How can I prevent the user to put characters in the TextArea for which no suggestions exist? 如何防止用户将字符放入没有建议的TextArea中?

I think the SuggestBox examines the text that has been put into the TextArea , and then displays the suggestions. 我认为SuggestBox会检查已放入TextArea的文本,然后显示建议。 But how could I prevent characters that do no match anymore? 但是,如何防止不再匹配的字符呢?

If you really need that 如果您真的需要

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

And then 接着

SuggestBox suggestBox = new SuggestBox(myData,area);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM