Note that there are some explanatory texts on larger screens.

plurals
  1. POSuggestBox GWT showing all options on Enter key
    text
    copied!<p>I need to create a SuggestBox that will show all options on pressing the Enter key. I have written the following implementation, and it seems to be working fine. I would like someone to review my implementation and let me know if it will cause problems in any particular scenario. Also, the SuggestOracle to be passed to this SuggestBox should have the default suggestions set, by calling the method setDefaultSuggestions() on MultiWordSuggestOracle. Any user of my SuggestBox should be transparent to this fact. Hence I guess I will need to wrap (or extend) MultiWordSuggestOracle to do the default suggestions settings. Can you please recommend what will be a good way of doing this? </p> <pre><code>public class SuggestBoxWithAllOptions extends SuggestBox implements KeyPressHandler { public SuggestBoxWithAllOptions(MultiWordSuggestOracle oracle) { super(oracle); this.addKeyPressHandler(this); } @Override public void onKeyPress(KeyPressEvent event) { char c = event.getCharCode(); int i = this.getText().length(); if (c == KeyboardListener.KEY_ENTER &amp;&amp; i == 0) { /* Since the query string is null, the default suggestions will get listed */ this.showSuggestionList(); } } } /* Code for initializing the SuggestBox */ List&lt;String&gt; suggestions = new ArrayList&lt;String&gt;(); suggestions.add("Tablet"); suggestions.add("Capsule"); MultiWordSuggestOracle myOracle = new MultiWordSuggestOracle(); myOracle.addAll(suggestions ); myOracle.setDefaultSuggestionsFromText(suggestions); SuggestBox mySuggest = new SuggestBoxWithAllOptions(myOracle); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload