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

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

Open
AngelGris opened this issue Jun 24, 2015 · 14 comments
Open

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

AngelGris opened this issue Jun 24, 2015 · 14 comments

Comments

@AngelGris
Copy link

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
Copy link

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? 👎

@AngelGris
Copy link
Author

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
Copy link

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

@bandaot
Copy link

bandaot commented Jun 27, 2015

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

bandaot added a commit to bandaot/yii2-widget-typeahead that referenced this issue Jun 27, 2015
bandaot added a commit to bandaot/yii2-widget-typeahead that referenced this issue Jun 27, 2015
gabrieljenik added a commit to gabrieljenik/typeahead.js that referenced this issue Oct 29, 2015
Merging into src files the changes suggested in issue twitter#1299.
When suggestions length equals the limit, no data was shown, as slice was asked to cut zero elements.

The bug also caused strange behavior when suggestion's length is higher than limit, as negative indexes were introduced.
@gabrieljenik
Copy link

This issue was not merged into the source files.
Created PR for that: #1420
I guess this would be later updated into the dist files, right?

@aholland
Copy link

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

@gabrieljenik
Copy link

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

@AdmirTomaz
Copy link

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
Copy link

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
#1299 (comment)
.

@AdmirTomaz
Copy link

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
Copy link

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

@AdmirTomaz
Copy link

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

@tswaters
Copy link

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: corejavascript/typeahead.js@a52bd45

@alexloginov
Copy link

Hi guys! Is it resolved already?

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

8 participants