I’m trying to impliment jqueryui’s autocomplete for multiple values but am having trouble. Options pop up fine when I first begin typing a name, but once that name is selected, a comma is added to the list and I no longer get options as I type. The code I have is below.
function fillAutoComplete(friends_list) {
$('input#opponents').autocomplete({
minLength:0,
source: $.map(friendList, function(item) {
return {
label: item.name,
value: item.name,
id: item.id
}
}),
focus: function() {return false},
multiple: true,
select: function(event, ui) {
var terms = (this.value).split(/,\s*/);
terms.pop();
terms.push(ui.item.value);
terms.push("");
this.value = terms.join(", ");
var temp = $('input#oppID').val();
if(temp != "") {
$('input#oppID').val(temp + "," + ui.item.id);
} else {
$('input#oppID').val(ui.item.id);
}
return false;
}
});
}
Thanks.
I had to do something very similar to this recently.
You need something like the following: