Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typeahead.js - Show that there are more results

I am using typeahead.js and everything works fine for me, except one thing:

I display only 5 entries in the suggestion dropdown, but if there are more results, I would like to show the user, that there are more results (but not the results itself, just the info, that there are more results) so that he goes on typing.

  • I don't want a scrollbar
  • I don't want to show the other results
  • Just an info, that there are more results

Please see screen attached.

enter image description here

like image 936
bernhardh Avatar asked Aug 21 '14 22:08

bernhardh


1 Answers

You can use a filter that just pulls out the length. In this example, only 20 results would be shown but I wanted people to know if there were more results not being displayed. See this for putting the results in a footer.

    var addresses = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('number'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        limit: 20,
        remote: {
            url: 'url?q=%QUERY',
            filter: function(list) {
                $('#search-total').html(list.length);
                return list;
            }
        }
    });
like image 194
Dan G Avatar answered Nov 10 '22 00:11

Dan G