我已经使用 GWTSuggestBox
获取用户输入并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);