bassjobsen / Bootstrap-3-Typeahead

The Typeahead plugin from Twitter's Bootstrap 2 ready to use with Bootstrap 3 and Bootstrap 4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I write one item in the result array in one place and the rest in another?

claracena opened this issue · comments

Hi,

I have the following script:

$('#usuario-buscar').typeahead({
minLength: 4,
highlight: true,
autoSelect: false,
source: function (query, result) {
$.ajax({
url: "user-filter.php",
data: 'query=' + query,
dataType: "json",
type: "POST",
success: function (data) {
result($.map(data, function (item) {
$('#usuario-buscar-id').val(item['user_id']);
return(item['apellido'] + ' ' + item['primer_nombre'] + ' - ' + item['nombre_usuario']);
}));
}
});
}
});

What I need to to is return the formatted result to the .typeahead textbox but the id of the selected item in another "hidden" textbox. Is it possible? In the example I get one of the possible IDs but not the one I select from the list.

Thanks!