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 not showing all results if less than limit #1232

Open
islopma opened this issue May 12, 2015 · 38 comments
Open

typeahead not showing all results if less than limit #1232

islopma opened this issue May 12, 2015 · 38 comments

Comments

@islopma
Copy link

islopma commented May 12, 2015

I'm using typeahead with the following code:

$('#questionId .typeahead').typeahead(null, {
    name: 'questions',
    displayKey: 'question',
    source: questionsList,
    limit: 10,
    templates: {
        empty: '<p>message</p>',
        suggestion: Handlebars.compile('<p>{{question}}</p>')
    }
})

Where 'questionsList' is a Bloodhound instance. The suggestions seem to be working fine when the query's number of matches is greater than 'limit' (10 in this case). But the problem is when the number of matches is <= limit. In that case, the number of suggestions displayed is max(limit - results, results). For instance, in my case when the query returns 10 matches, 0 results are displayed. When the query returns 8 matches, 2 results are displayed. When the query returns 3 matches, 3 results are displayed, and so on.

@rafaelGuerreiro
Copy link

+1. The problem seems to be on Dataset's update function... On the inner function called async.

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)); // IMHO this slice shouldn't exist...
        that.async && that.trigger("asyncReceived", query);
    }
}

@coopy
Copy link

coopy commented May 13, 2015

Both PRs close the issue. #1212 comes with a test ;]

@javiercejudo
Copy link

This is solved in #1200 but it isn't in master

@ShNURoK42
Copy link

Thx. I catched this.

@louy
Copy link

louy commented Jun 7, 2015

Can we expect this anytime soon?

@akashvarlani
Copy link

Thanks @rafaelGuerreiro. You just saved my day 👍

@alexfarrill
Copy link

+1 for merging this

dzhdmitry added a commit to dzhdmitry/typeahead.js that referenced this issue Jun 11, 2015
@dmitry027
Copy link

+1 for merging

@razvaniacob
Copy link

+1 for merging this

@luanau
Copy link

luanau commented Jul 15, 2015

Interestingly, in my case no result is displayed when the number of suggestions exactly equals the limit I set. I use the three parameters async source function.

@droghio
Copy link

droghio commented Jul 20, 2015

This is a very nasty bug, looks like a patch has been out for almost three months ( merge #1212 ), but still hasn't been pulled into main. Considering the popularity of the project I hope they patch the issue soon.

@unibasil
Copy link

+1 @luanau, the same thing happens. Zero results are shown when limit is equal to number of suggestions, 1 result when limit is greater by one and so on.

@unibasil
Copy link

+1 @droghio, it's strange there is no new release yet.

@louy
Copy link

louy commented Jul 30, 2015

For anybody who wants a quick solution, just use Infinity as the limit, and limit the results in your server response.

@normancesar
Copy link

@louy Thanks, that works perfectly and probably the right solution anyway, why return more results than you are going to display? Waste of network traffic

@louy
Copy link

louy commented Jul 30, 2015

it is, but you have to subtract results from sync callback as well, and then slice or something.

@suj87
Copy link

suj87 commented Aug 5, 2015

I have just spent hours trying to work out what the f***k was going on here and just come across this. I'm assuming this still isn't fixed in 0.11.1 (the ver I'm using)? I had my limit set to 7. I'm returning no more than 7 results from the server. When the result set is e.g. 5, it's only showing the first 2 etc.

@timkinnane
Copy link

I had the same problem and found the best option was to use a fork that already resolved this issue.
https://github.com/per-nilsson/typeahead.js/tree/fix-async-render-dist

@unibasil
Copy link

unibasil commented Aug 6, 2015

@louy, but if one has no access to server configuration or using third-party API?

@timkinnane, thanks, it's better than apply patch just in building process.

@suj87
Copy link

suj87 commented Aug 6, 2015

I decided to go for the lazy option and just set limit to 400 (though based on my wanted limit of 7 I guess 14 would work just as well).

@phlegx
Copy link

phlegx commented Aug 26, 2015

👍 for merging

@oliroy
Copy link

oliroy commented Sep 9, 2015

+1 for merging

@pflannery
Copy link

+1

@BenjaminRCooper
Copy link

Could limit using Nth-Child in CSS as a workaround too.

@markau
Copy link

markau commented Feb 10, 2016

@louy Thank you for the Infinity option

@namtab00
Copy link

This repo seems abandoned.. some kind souls continue maintaing it here: https://github.com/corejavascript/typeahead.js
I'd say the useful thing to do is sending pull request there.

@dlo
Copy link

dlo commented Jul 14, 2016

Thanks @namtab00 for pointing out a maintained fork. As of July 2016, this bug has still not been fixed.

@louy's solution worked great for me.

@natecox
Copy link

natecox commented Jul 14, 2016

I've been using https://github.com/corejavascript/typeahead.js for a while now instead of this repo, and it works great. highly suggest migrating over there.

@pam81
Copy link

pam81 commented Aug 17, 2016

I confirm too, this bug has still not been fixed.

@alestuber
Copy link

+1 for using Infinity and limiting on the backend.

But nevertheless this should be patched on master.

There's no one working on this repository anymore?

@natecox
Copy link

natecox commented Aug 31, 2016

@alestuber This repo is as dead as dead gets as far as I can tell. https://github.com/corejavascript/typeahead.js is the place to go.

@jerefrer
Copy link

For Rails devs here, you can use this fork of the twitter-typeahead-rails gem.

scuy added a commit to dainst/ariadne-portal that referenced this issue Jan 17, 2017
tbaddade added a commit to tbaddade/redaxo_watson that referenced this issue Feb 4, 2017
dtao added a commit to dtao/boxofficehawk that referenced this issue Jul 11, 2017
I noticed while investigating a bug that the typeahead library is
essentially abandoned:

twitter/typeahead.js#1232

One of the comments in the above thread mentions this fork of the
library, which is actively maintained and includes a fix for said bug.
colinpetruno added a commit to colinpetruno/scheduleless that referenced this issue Oct 13, 2017
Fixes #131, weird typeahead bug, read about it here
twitter/typeahead.js#1232
juanluisrp added a commit to juanluisrp/core-geonetwork that referenced this issue Dec 6, 2018
When the server returns less suggestions than what is configured as limit for
the autocompleter, it only shows the first one, not adding the others to the
suggestions list. This is a bug detected in Typeahead library, see
twitter/typeahead.js#1232.

This library seems not to be actively maintained by Twitter anymore (latest commits
were in 2015). I've taken the patch from a fork, Corejs Typeahead.js
https://github.com/corejavascript/typeahead.js

https://github.com/corejavascript/typeahead.js/blob/107a9b0d002e549be746d93a1fbcde05853d745a/src/typeahead/dataset.js#L269-L281
juanluisrp added a commit to geonetwork/core-geonetwork that referenced this issue Dec 10, 2018
When the server returns less suggestions than what is configured as limit for
the autocompleter, it only shows the first one, not adding the others to the
suggestions list. This is a bug detected in Typeahead library, see
twitter/typeahead.js#1232.

This library seems not to be actively maintained by Twitter anymore (latest commits
were in 2015). I've taken the patch from a fork, Corejs Typeahead.js
https://github.com/corejavascript/typeahead.js

https://github.com/corejavascript/typeahead.js/blob/107a9b0d002e549be746d93a1fbcde05853d745a/src/typeahead/dataset.js#L269-L281
juanluisrp added a commit to juanluisrp/core-geonetwork that referenced this issue Dec 10, 2018
Backport of geonetwork#3332.

When the server returns less suggestions than what is configured as
limit for the autocompleter, it only shows the first one, not adding the
others to the suggestions list. This is a bug detected in Typeahead
library, see twitter/typeahead.js#1232.

This library seems not to be actively maintained by Twitter anymore
(latest commits were in 2015). I've taken the patch from a fork, Corejs
Typeahead.js https://github.com/corejavascript/typeahead.js

https://github.com/corejavascript/typeahead.js/blob/107a9b0d002e549be746d93a1fbcde05853d745a/src/typeahead/dataset.js#L269-L281
juanluisrp added a commit to geonetwork/core-geonetwork that referenced this issue Dec 10, 2018
)

Backport of #3332.

When the server returns less suggestions than what is configured as
limit for the autocompleter, it only shows the first one, not adding the
others to the suggestions list. This is a bug detected in Typeahead
library, see twitter/typeahead.js#1232.

This library seems not to be actively maintained by Twitter anymore
(latest commits were in 2015). I've taken the patch from a fork, Corejs
Typeahead.js https://github.com/corejavascript/typeahead.js

https://github.com/corejavascript/typeahead.js/blob/107a9b0d002e549be746d93a1fbcde05853d745a/src/typeahead/dataset.js#L269-L281
@inandi
Copy link

inandi commented Mar 19, 2019

For anybody who wants a quick solution, just use Infinity as the limit, and limit the results in your server response.

limit: Infinity
thanks for saving my day. peace!!!

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