lekoala / bootstrap5-autocomplete

Autocomplete for Bootstrap 5 (and 4!)
MIT License
87 stars 16 forks source link

noEmptyQuery config to prevent fetch from server when autocomplete input is empty #49

Closed mjradwin closed 4 months ago

mjradwin commented 4 months ago

This PR adds a new noEmptyQuery option (default false) that suppresses the fetch from remote when the autocomplete input field is empty. Most useful when using liveServer and trying to reduce network traffic.

lekoala commented 4 months ago

interesting

i may be missing something but isn't suggestionsThreshold enough to deal with this? maybe this could be checked in order to avoid unecessary queries

lekoala commented 4 months ago

can you explain when this would be needed? when using suggestionsThreshold _shouldShow will return false if below that length and no query will be made

mjradwin commented 4 months ago

Thanks for the feedback here. It looks like the root cause of the problem was a race condition on focus handler. I had a focus handler that set the autocomplete input field to the empty string, which is firing at the same time as your focus handler (which in turn calls showOrSearch()). Indeed, we don't need this pull request after all. Closing this as unneeded.