我在GWT中有一个SuggestionBox。有没有办法在它模糊时清除它(除非用户做出选择,在这种情况下应该采取行动)?
答案 0 :(得分:0)
使用ValueChangeHandler
:
注意:ValueChange
事件与Blue
事件具有相同的行为,但只有在SuggestBox
中更改了值时才触发该事件。
class MyMultiWordSuggestOracle extends MultiWordSuggestOracle {
private Set<String> values = new HashSet<String>();
@Override
public void add(String value) {
super.add(value);
values.add(value);
}
@Override
public void clear(){
super.clear();
values.clear();
}
public boolean contains(String value) {
return values.contains(value);
}
}
你编码:
final MyMultiWordSuggestOracle oracle = new MyMultiWordSuggestOracle();
oracle.add("A");
oracle.add("AB");
oracle.add("BCD");
oracle.add("BCDE");
final SuggestBox suggestionBox = new SuggestBox(oracle);
suggestionBox.addValueChangeHandler(new ValueChangeHandler<String>() {
@Override
public void onValueChange(ValueChangeEvent<String> event) {
if (!oracle.contains(event.getValue())) {
suggestionBox.setValue("");
}
}
});
答案 1 :(得分:0)
添加BlurHandler:
suggestionBox.getValueBox().addBlurHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
// your code goes here
}
});