I'd like to show all Typeahead items when the text-input (id="Questions") get focus. How can I do it?
Javascript:
function SetTypeahead() {
$("#Questions").typeahead({
minLength: 0,
source: [
"Q1?",
"Q2?",
"Q3?",
"@4?"
]
});
}
For me, the $viewValue was null upon selection which was preventing the list from displaying. My solution was to set the filter to an empty string when $viewValue was null.
Check this pull request from theophraim's typeahead, he has included this functionality, but it is yet to be merged.
The last version
v3.1.0
of typeahead had an explicit optionGet the latest bootstrap typeahead plugin v2.1.2 at https://raw.github.com/michaelcox/bootstrap/6789648b36aedaa795f1f5f11b4da6ab869f7f17/js/bootstrap-typeahead.js
This update will allow minLength of zero to enable show all for typeahead
Then you have to attach the onFocus event to your element, because it's not defined by the plugin:
it's a also a good idea to overwrite the bootstrap typeahead css class locally to set max-height and vertical scroll for the results in case there are too many results.
There is a closed issue about it on typeahead github at the following link: https://github.com/twitter/typeahead.js/issues/462
You will find out that, as described by jharding:
Though a previous message by pricey shows how you can implement it.
You can also go for more recent version https://github.com/bassjobsen/Bootstrap-3-Typeahead
Here is my solution:
Init typeahead
$("#FinalGrades", context).typeahead({ minLength: 0, items: 10, scrollBar: true, source: finalGrades });
Trigger textbox event