关于GWT模糊的清除SuggestBox

时间:2014-03-25 01:25:42

标签: gwt suggestbox

我在GWT中有一个SuggestionBox。有没有办法在它模糊时清除它(除非用户做出选择,在这种情况下应该采取行动)?

2 个答案:

答案 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
    }
});