Bootstrap-3-Typeahead
Bootstrap-3-Typeahead copied to clipboard
suggestion list not being shown
I follow the documentation but nothing is working for me. I am loading my data from remote :
Here is the structure of data coming from remote:
{"source":[{id:1,name:"coke"},{id:2,name:"papa"},{id:3,name:"mama"}]}
on client side here is my first code I tried with :
var typeaheadInput = $('input[name=name]');
typeaheadInput.typeahead({
source: function (query) {
if (query.length > 3) {
return $.get('/suggestproduct/' + query, function (data) {
return data.source;
});
}
},autoSelect:true
});
Nothing worked with that code. The information are reaching the browser but are not being shown.
What I want is to show to the user the value of name field and pass id value of the selected to a hidden field.
How can I acheive that?
Try with the following code:
var typeaheadInput = $('input[name=name]');
typeaheadInput.typeahead({
autoSelect:true,
minLength: 3,
source: function (query, process) {
return $.get('/suggestproduct/' + query, function (data) {
process(data.source);
});
}
});