Hey I found a solution to this so I am just posting the code below in case it helps anyone else.
var lastKey = -1;
var performSearch = true;
$("#Test").autocomplete({
minLength: 0,
source: function (request, response) {
if (performSearch) {
if (lastKey >= 0) {
response($.ui.autocomplete.filter(
availableTags, extractLast(request.term.substring(lastKey + 1))));
}
}
},
focus: function () {
return false;
},
select: function (event, ui) {
var terms = split(this.value);
terms.pop();
terms.push(ui.item.value + "%");
terms.push("");
this.value = this.value.substr(0, lastKey + 1);
this.value += terms.join("");
return false;
}
}).on("keypress", function (e) {
var keys = [];
keys.unshift(e.which);
if (String.fromCharCode(keys[0]) == "%") {
lastKey = $("#Test").val().length;
}
}).on("keydown", function (event) {
if (event.keyCode == 8 || event.keyCode == 32) {
performSearch = false;
} else {
performSearch = true;
}
});
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}