I am using bootstrap typeahead to search like this:
$('.lookup').typeahead({
source: function (query, process) {
return $.getJSON(
'json_autocomplete.php',{ query: query },
function (data) {
var newData = [];
$.each(data, function(){
newData.push(this.label);
//populate hidden field with id
$('#contact_id').val(this.id);
});
return process(newData);
});
}
});
The JSON data looks like this:
[{"label":"Contact: Jeff Busch-> Busch, Jeff: 1975-11-24","value":"Busch, Jeff","id":"2096"}, ...
It is working great. When the user starts typing the "label" data is shown in a list under the input. HOWEVER, once the user clicks one of the list items, I want the "value" text to appear in the input text box not all the label info that was searched!
Is this possible?
Here's a fiddle: