A {@link SuggestBox} is a text box or text area which displays apre-configured set of selections that match the user's input. Each {@link SuggestBox} is associated with a single {@link SuggestOracle}. The {@link SuggestOracle} is used to provide a set of selections given aspecific query string.
By default, the {@link SuggestBox} uses a {@link MultiWordSuggestOracle} asits oracle. Below we show how a {@link MultiWordSuggestOracle} can beconfigured:
MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); oracle.add("Cat"); oracle.add("Dog"); oracle.add("Horse"); oracle.add("Canary"); SuggestBox box = new SuggestBox(oracle);
Using the example above, if the user types "C" into the text widget, the oracle will configure the suggestions with the "Cat" and "Canary" suggestions. Specifically, whenever the user types a key into the text widget, the value is submitted to the
MultiWordSuggestOracle
.
Note that there is no method to retrieve the "currently selected suggestion" in a SuggestBox, because there are points in time where the currently selected suggestion is not defined. For example, if the user types in some text that does not match any of the SuggestBox's suggestions, then the SuggestBox will not have a currently selected suggestion. It is more useful to know when a suggestion has been chosen from the SuggestBox's list of suggestions. A SuggestBox fires {@link SuggestionEvent SuggestionEvents}whenever a suggestion is chosen, and handlers for these events can be added using the {@link #addEventHandler(SuggestionHandler)} method.
CSS Style Rules
- .gwt-SuggestBox { the suggest box itself }
- .gwt-SuggestBoxPopup { the suggestion popup }
- .gwt-SuggestBoxPopup .item { an unselected suggestion }
- .gwt-SuggestBoxPopup .item-selected { a selected suggestion }
@see SuggestOracle
@see MultiWordSuggestOracle
@see TextBoxBase