typeahead.js: typeahead not showing all results if less than limit

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.

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 20
  • Comments: 38

Commits related to this issue

Most upvoted comments

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

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

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

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.

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.

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.

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.

@louy the Infinity trick worked for me as well. Thanks!

There’s a simple way of solving this: put the limit to 20 and divide it by 2 in your server side.

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