Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeahead.js 0.11.1 doesn't render results when results are less than limit #1795

Open
wpconsulate opened this issue Nov 9, 2020 · 3 comments

Comments

@wpconsulate
Copy link

I'm using typeahead 0.11.1 on a website and making a remote call to the public API for search.
I noticed that typeahead works fine when there are more than limit records ( default limit is 5 as you guys have set it ) but when API returns less than 5 results. typeahead just shows 1 single result there.

I noticed there was a similar kind of issue earlier link here
https://stackoverflow.com/questions/31007825/bootstrap-typeahead-not-showing-hints-as-expected

and after checking the typeahead.bundle.js I found the suggested solution is implemented. But this solution isn't working in the latest release.

I noticed the issue is being the number of results returned by the API.

So on LINE 1723

I changed the following code
rendered += suggestions.length;
To
if(suggestions.length > that.limit) rendered += suggestions.length;

and this fixed the issue for me. I haven't tested it much yet will report if found anything.

thanks

@pursca
Copy link

pursca commented Jan 16, 2022

the logic inside this function is wrong
function async(suggestions) {
suggestions = suggestions || [];
if (!canceled && rendered < that.limit) {
that.cancel = $.noop;
rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit - rendered));
that.async && that.trigger("asyncReceived", query);
}
}
it should be - rendered += suggestions.length; should be put after that._append()
function async(suggestions) {
suggestions = suggestions || [];
if (!canceled && rendered < that.limit) {
that.cancel = $.noop;
that._append(query, suggestions.slice(0, that.limit - rendered));
rendered += suggestions.length;
that.async && that.trigger("asyncReceived", query);
}
}

@john-999
Copy link

Recommended new solutions (without jQuery dependencies):

  1. Tarek Raafat's "autoComplete.js" (can be used in existing forms): https://github.com/TarekRaafat/autoComplete.js

  2. "Algolia autocomplete" (but creates a form element, so not usable within existing forms, only as a standalone element): https://github.com/algolia/autocomplete

@jlbooker
Copy link
Contributor

jlbooker commented Oct 25, 2022

Duplicate of #1232

You can also find a fix for this included in the fork at: https://github.com/corejavascript/typeahead.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants