Typeahead.js: Remote completion

Created on 7 May 2015  路  43Comments  路  Source: twitter/typeahead.js

I have a very strange behavior with remote data.
I've made a self explaining JSFiddle that you can find here.

It works well with 1 result, or two, or more than 5. Otherwise it's completly messed up.

Most helpful comment

I've made a small modification to the source of typeahead.js because I need this thing to work as soon as possible.

The problem comes from "typeahead.bundle.js:1719" :

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);
    }
}

I've replaced :

rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit - rendered));

by :

suggestions = (suggestions || []).slice(0, that.limit);
rendered = suggestions.length;
that._append(query, suggestions);

and it seems to work.. I have no idea of possible side effects of this modification, so I hope someone with enough knowledge of the library can check this.

All 43 comments

I've made a small modification to the source of typeahead.js because I need this thing to work as soon as possible.

The problem comes from "typeahead.bundle.js:1719" :

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);
    }
}

I've replaced :

rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit - rendered));

by :

suggestions = (suggestions || []).slice(0, that.limit);
rendered = suggestions.length;
that._append(query, suggestions);

and it seems to work.. I have no idea of possible side effects of this modification, so I hope someone with enough knowledge of the library can check this.

+1 came here with the same issue and general conclusion

+1

I got the same issue. I have added your code to the JS. However it still shows only 5 out of ten search results but now atleast it shows all results up to 5 instead of sometimes 2 out of 3.

Any workaround to let it show all 10 results from bloodhound?

This is the code I used to replace the aforementioned 2 lines (small difference to account for already rendered suggestions):

suggestions = suggestions.slice(0, that.limit - rendered);
rendered += suggestions.length;
that._append(query, suggestions);

I'll see if I can get a pull with a corresponding test up today.

@DutchEcho did you set the limit option to 10? The default is 5.

Gues the limit is new as it worked before. I have added limit: 10 now in my typeahead and it works like a charm again. Thanks @joekur

Hi guys, I found this report Googling around. Could you kindly take a look at this http://stackoverflow.com/questions/30370496/typeahead-js-bloodhound-display-just-one-result and confirm me that the problem I've is due to this bug? Otherwise I'll open a new bug since I cannot find any other cause here..

Confirmed! I applied @joekur suggested workaround and the issue is gone... I hope this will be fixed soon on the official package!

I also got this issue, the fix is in #1212 but hasn't been merged yet.

Duplicate of #1185

Bumping, this is still open and unfixed.

The fix has still not been merged

+1 There is still bug in current version !!!

Just wasted a whole day trying to get remote to work thinking there was something bad with my code, can you guys fix your shit? @jharding The solution has already been given to you, just merge it

Twitter abandonned the project, here is a maintained fork with the fix merged: https://github.com/corejavascript/typeahead.js

I actually didn't have to replace the code, only add limit:10 to typeahead and my results started showing. So far so good. Thanks for the pointer @jarthod, I'll look to that repo.

+1

+1 - that last bit of code posted by @joekur fixed my issue of typeahead chopping off the last suggestion when 5 or less suggestions were returned by my api & bloodhound. Thank you!

+1 to @Stnaire for posting the original code.

+1

+1 @Stnaire @joekur

+1

Same problem here, +1

+1

+1

+1

@xrnm I solved the issue by taking the version from corejavascript forked version.

+1

Same problem here...
+1 @rosskevin his solution works

Maybe it's time to stop using this no more maintained library. For my usage, Select2 was enough. Otherwise you can also try awesomplete.

This fix works , just somthing if you have no limit set you should use :
suggestions = (suggestions || []).slice(0, that.limit+1);

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1, thx for this fix

(:

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steswinbank picture steswinbank  路  5Comments

GreatPotato picture GreatPotato  路  8Comments

palintropos picture palintropos  路  4Comments

Neeeeena picture Neeeeena  路  3Comments

jimmynotjim picture jimmynotjim  路  8Comments