Class SuggestBox

All Implemented Interfaces:
IsEditor<LeafValueEditor<String>>, HasAllKeyHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasAttachHandlers, HasSelectionHandlers<SuggestOracle.Suggestion>, HasValueChangeHandlers<String>, HasHandlers, EventListener, TakesValue<String>, FiresSuggestionEvents, Focusable, HasAnimation, HasEnabled, HasFocus, HasText, HasValue<String>, HasVisibility, IsRenderable, IsWidget, SourcesChangeEvents, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents

A SuggestBox is a text box or text area which displays a pre-configured set of selections that match the user's input. Each SuggestBox is associated with a single SuggestOracle. The SuggestOracle is used to provide a set of selections given a specific query string.

By default, the SuggestBox uses a MultiWordSuggestOracle as its oracle. Below we show how a MultiWordSuggestOracle can be configured:

   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 SelectionEvents whenever a suggestion is chosen, and handlers for these events can be added using the addSelectionHandler(SelectionHandler) method.

CSS Style Rules

.gwt-SuggestBox
the suggest box itself
See Also: