twitter / typeahead.js

typeahead.js is a fast and fully-featured autocomplete library
http://twitter.github.io/typeahead.js/
MIT License
16.52k stars 3.21k forks source link

Not showing hints when number of hints equals (limit - rendered) #1299

Open AngelGris opened 9 years ago

AngelGris commented 9 years ago

When getting remote hints, if the number of hints equals (limit - rendered) since in typeahead.bundle.js line 1723 it runs:

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

So if the number of hints equals (limit - rendered) then it'll append an empty array (suggestions.slice(0, 0)). To prevent this just switch those two lines so that it first appends the suggestions and only then increases the number of rendered hints:

that._append(query, suggestions.slice(0, that.limit - rendered);
rendered += suggestions.length;
gaborbernat commented 9 years ago

I think this is a significant bug, assume you set the limit to 15. You get 9 items from remote. The slice of 15-9 is 6, so only the first 6 will be used. Like what? :-1:

AngelGris commented 9 years ago

Yeah, a real problem. But switching those two lines of code to append first and only then increase the number of rendered hints solves it.

gaborbernat commented 9 years ago

@jharding can we make a quick bug fix release with this?

bandaot commented 9 years ago

Oh, shit! This bug have waste whole my afternoon...

gabrieljenik commented 8 years ago

This issue was not merged into the source files. Created PR for that: https://github.com/twitter/typeahead.js/pull/1420 I guess this would be later updated into the dist files, right?

aholland commented 8 years ago

The problem is that twitter/typeahead is no longer maintained. I too fixed this bug - see https://github.com/twitter/typeahead.js/pull/1416 - but there is a very long queue of pull requests. The new active project is https://github.com/corejavascript/typeahead.js

gabrieljenik commented 8 years ago

Oh! I though about that! but didn't find any notice about that! Maybe editing the readme?

AdmirTomaz commented 8 years ago

macgyver solution is not correct, but it works = D puts limit: limit: 999999999999999999999999999999999 It worked with me because I'm taking data dynamically, so I limit the items in mysql select: $ animals = $ mysqli-> prepare ("SELECT id_tipo_venda, id, name, foto1, sex FROM animals WHERE name LIKE ORDER by name, id LIMIT 7");

aholland commented 8 years ago

Whatever you're trying to fix or work around has probably already been fixed on the active fork, which is over at https://github.com/corejavascript/typeahead.js

On 31 October 2015 at 13:19, AdmirTomaz notifications@github.com wrote:

macgyver solution is not correct, but it works = D puts limit: limit: 999999999999999999999999999999999 It worked with me because I'm taking data dynamically, so I limit the items in mysql select: $ animals = $ mysqli-> prepare ("SELECT id_tipo_venda, id, name, foto1, sex FROM animals WHERE name LIKE ORDER by name, id LIMIT 7");

— Reply to this email directly or view it on GitHub https://github.com/twitter/typeahead.js/issues/1299#issuecomment-152734919 .

AdmirTomaz commented 8 years ago

No, I tested this, I saw that you had posted above, the js are the same as I had here, it is the same way =(

aholland commented 8 years ago

Sorry, didn't realise it was the same thread.

AdmirTomaz commented 8 years ago

if they find a better solution, please let here. =D

tswaters commented 8 years ago

The corejs fork has updated it in master, but they haven't pushed up a new version yet so if you do a straight bower install you'll get the same behavior. See: https://github.com/corejavascript/typeahead.js/commit/a52bd457977fae264d1f90564bfa1fbddbbf7c9d

alexloginov commented 7 years ago

Hi guys! Is it resolved already?