簡體   English   中英

防止在SuggestBox中輸入無效的用戶?

[英]Prevent invalid user input in SuggestBox?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM