1

Hie

We are using a gwt SuggestBox which shows suggestions as user starts typing into this box. however, there is a possibility that end user just type something and do not select anything from the list.

we want to avoid this use case and display error if user do not select anything from the list.

any advise on how can we implement this? The real issue is how to get the list of current suggestions which are display? i dont see any method in suggestOracle class to get the list?

So, anyway without firing another query to get the current list of displayed suggestions?

RAS
  • 8,100
  • 16
  • 64
  • 86
Vik
  • 8,721
  • 27
  • 83
  • 168

1 Answers1

1

Listen to the ValueChangeEvent of the underlying TextBox and check if the value matches any of the selectable values (you can make a call to the SuggestOracle and display an error if it returns zero or more than 1 results; if it returns a single result, you might want to check whether the values are equal).

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • so is there a way to get the list of currently shown suggestions? could not find in apis/methods in javadoc – Vik Jun 13 '12 at 17:11
  • `suggest.getSuggestOracle().requestSuggestions(new Request(suggest.getText()), new Callback() { public void onSuggestionReady(Request req, Response resp) { if (resp.getSuggestions().length() != 1 || !resp.getSuggestions().get(0).equals(req.getQuery()) { /* error */ } });` – Thomas Broyer Jun 14 '12 at 00:09
  • this will fire a query again to get the list again. That is what i want to avoid as my implementation gets the data via RPC call which is costly – Vik Jun 14 '12 at 02:22
  • Then add some local caching (you should already have implemented throttling, so adding caching is no big deal) – Thomas Broyer Jun 14 '12 at 09:51
  • Hie no sorry we have not implemented throttling. Please explain what is that? May be we are missing something big for our non profit app. – Vik Jun 15 '12 at 00:55
  • 1
    If you're sending out every single character typed by the user to your server, then making an additional request to verify that the value is valid is no big deal. If you care about the number of requests, then add throttling and caching: defer sending requests by a few milliseconds and cancel/reschedule at each new request (character typed), and cache results so your last request for verification won't reach the network. A good caching strategy will also wait of an ongoing equivalent request instead of making a new one. – Thomas Broyer Jun 15 '12 at 09:01
  • sounds interesting. Do you have any reference doc or implementation to do that? Right now to minimize a bit we fire request only when at least 3 chars are typed. – Vik Jun 15 '12 at 18:15
  • 1
    https://code.google.com/p/google-web-toolkit-incubator/source/browse/trunk/src/com/google/gwt/widgetideas/client/RPCSuggestOracle.java is a good start: it'll only send a request if one isn't pending a response already. Combine that with min-length, a slight delay before sending a request, and local caching. – Thomas Broyer Jun 15 '12 at 18:49