简体   繁体   中英

Typeahead / Bloodhound delayed suggestions

I have a few fields that accept a three letter shortcode for locations. These shortcodes are not commonly known except to a few 'long term' users.. example

LND - London
SWN - Swindon

The drop down box is based on the full name, and propagates the box with the short code. So if someone starts to type LON, they get the suggestion box of London (LND), click on it and the box fills with LND.

Easy enough.. HOWEVER.. it turns out there are more users who know the short codes that I anticipated.. so they are typing LND and getting a 'no suggestions' error.

Is it possible (cant see on bloodhound or typeahead docs, but only skim reading) to ONLY start offering suggestions when the fourth character typed.

SO if someone knows the three letter code, they wont get any error or suggestions, but as soon as someone types in a fourth character, suggestions start to list. This ensures that only someone typing in the full name of a location will get suggestions for the shortcode, and those using the shortcode can just enter it with no errors.

Thanks

You can set the minLength property for your typeahead. This ensures that no lookup's will be initiated until the user has entered enough characters. Like :

 $('#your-typeahead .typeahead').typeahead({
  minLength: 4
} 

That way you can ensure that users who know the short codes will not be presented with error's like 'no suggestions'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM