Why the suggestion list remains visible in GWT

126 Views Asked by At

I am working with suggestion box in gwt and added SelectionHandler and onFocusHandler to the suggestion box but after selection the suggestion list remains visible.. Which should not be the case.

What should I do to hide the suggestion list after selecting one of the suggestion.?

suggestBox.getValueBox().addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            if(suggestBox.getText().equals("")){
                suggestBox.setText(" ");
                suggestBox.showSuggestionList();
                suggestBox.setText("");
            }   
        }
    });

suggestBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {

        @Override
        public void onSelection(SelectionEvent<Suggestion> arg0) {
            if (arg0.getSelectedItem() instanceof Suggestion) {
                //code to take actions after selection
            }
        }
    });
1

There are 1 best solutions below

0
Davide Ungari On

What should I do to hide the suggestion list after selecting one of the suggestion.?

Why don't you hide the list in your selection handler?

    @Override
    public void onSelection(SelectionEvent<Suggestion> arg0) {
        if (arg0.getSelectedItem() instanceof Suggestion) {
            //code to take actions after selection
        }
        DefaultSuggestionDisplay display = (DefaultSuggestionDisplay) suggestBox.getSuggestionDisplay();
        display.hideSuggestions();
    }