typeahead.js icon indicating copy to clipboard operation
typeahead.js copied to clipboard

Remote completion

Open Stnaire opened this issue 11 years ago • 43 comments

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.

Stnaire avatar May 07 '15 11:05 Stnaire

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.

Stnaire avatar May 07 '15 11:05 Stnaire

+1 came here with the same issue and general conclusion

joekur avatar May 07 '15 14:05 joekur

+1

hartwoolery avatar May 07 '15 20:05 hartwoolery

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?

DutchEcho avatar May 08 '15 13:05 DutchEcho

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.

joekur avatar May 08 '15 14:05 joekur

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

DutchEcho avatar May 08 '15 14:05 DutchEcho

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..

ZaneCEO avatar May 21 '15 10:05 ZaneCEO

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

ZaneCEO avatar May 21 '15 10:05 ZaneCEO

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

jarthod avatar May 26 '15 15:05 jarthod

Duplicate of #1185

jarthod avatar May 26 '15 16:05 jarthod

Bumping, this is still open and unfixed.

0x62 avatar Sep 03 '15 21:09 0x62

The fix has still not been merged

ChrisWoodlief avatar Oct 03 '15 22:10 ChrisWoodlief

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

mralexivy avatar Oct 05 '15 13:10 mralexivy

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

goyote avatar Oct 07 '15 19:10 goyote

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

jarthod avatar Oct 07 '15 20:10 jarthod

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.

rosskevin avatar Oct 16 '15 17:10 rosskevin

+1

outaTiME avatar Dec 03 '15 00:12 outaTiME

+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!

JustinWinthers avatar Dec 12 '15 02:12 JustinWinthers

+1 to @Stnaire for posting the original code.

JustinWinthers avatar Dec 12 '15 02:12 JustinWinthers

+1

maxaudrin avatar Dec 17 '15 10:12 maxaudrin