Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typeahead always shows only 5 suggestions maximum

I have the below code using Typeahead.js for suggestions. I have no major issues on the code as it works fine.

The minor issue I face is that any given time, I see only 5 suggestions even though there are more than 5 suggestions from the remote URL.

var isearch = new Bloodhound({     datumTokenizer: function(d) {           return Bloodhound.tokenizers.whitespace(d.value);      },     queryTokenizer: Bloodhound.tokenizers.whitespace,     remote: "http://localhost/search/get-data/%QUERY" });  isearch.initialize();    $("#search_box .typeahead").typeahead(null,{ name: "isearch",     displayKey: "value",     source: isearch.ttAdapter(),     templates: {          suggestion: Handlebars.compile("{{value}}")     } }); 

What I expect is that there are more suggestions, there should be a scroll bar for users to see.

like image 678
Purus Avatar asked Jun 01 '14 15:06

Purus


People also ask

How do you set a value in typeahead?

jQuery#typeahead('val', val) Sets the value of the typeahead. This should be used in place of jQuery#val.

What is a typeahead input?

The typeahead input fields are very popular in modern web forms. The main purpose of using typeahead is to improve the user experience by supplying hints or a list of possible choices based on the text they've entered while filling a form or searching something — like the Google instant search.

How do I disable typeahead?

To disable the autocomplete of text in forms, use the autocomplete attribute of <input> and <form> elements.

What is bloodhound typeahead?

Bloodhound is the typeahead. js suggestion engine. Bloodhound is robust, flexible, and offers advanced functionalities such as prefetching, intelligent caching, fast lookups, and backfilling with remote data.


2 Answers

In Typeahead version 0.11.1:

Specify "limit" during the instantiation of the typeahead object to set the number of suggestions to display e.g.

// Instantiate the Typeahead UI $('.typeahead').typeahead(null, {  limit: 10, // This controls the number of suggestions displayed  displayKey: 'value',  source: movies }); 

See a working example here:

http://jsfiddle.net/Fresh/ps4w42t4/


In Typeahead version 0.10.4.

The Bloodhound suggestion engine has a default value of five for the "limit" option (i.e. The max number of suggestions to return from Bloodhound#get)

You can increase the limit by specifying the desired value when you instantiate your Bloodhound object. For example, to specify a limit of 10:

var isearch = new Bloodhound({  datumTokenizer: function(d) {       return Bloodhound.tokenizers.whitespace(d.value);   },  queryTokenizer: Bloodhound.tokenizers.whitespace,  remote: "http://localhost/search/get-data/%QUERY",  limit: 10 }); 

An example of an instance of Typeahead where the limit is set to 10 can be found here:

http://jsfiddle.net/Fresh/w03a28h9/

like image 108
Ben Smith Avatar answered Oct 05 '22 23:10

Ben Smith


In my case 'limit' option worked but in different way. I had to put limit option on typeahead instead of Bloodhound. I am posting my case, so that it might help someone.

bloodhoundSuggestionEngine = new Bloodhound({ datumTokenizer : function(d) { return Bloodhound.tokenizers.whitespace(d.key); }, queryTokenizer : Bloodhound.tokenizers.whitespace, local : myOptions });  $("#myinputbox").typeahead({ minLength : 3, highlight : true }, { displayKey : 'key', source : bloodhoundSuggestionEngine.ttAdapter(), limit: 10 }); 
like image 40
Atul Kumbhar Avatar answered Oct 05 '22 22:10

Atul Kumbhar