My auto-complete source list is a little bit like this:
var items = ['UK', 'IE', 'BE', 'NL', 'PLC'];
I am trying to make sure that the result set from my auto-complete always contains a
specific term (in this case PLC).
I have tried is adding PLC to the source list, then overriding the autocomplete result filter (see here).
I can get it to return “PLC” regardless of what is typed in like this:
$("#autocomplete").autocomplete({
source: function(request, response) {
// The term the user searched for;
var term = request.term;
// Extract matching items:
var matches = $.grep(items, function(item, index) {
return /PLC/.test(item);
});
// let autocomplete know the results:
response(matches);
}
});
http://jsfiddle.net/GarethPN/xbZhr/6/
But how would I use the term variable in the regular expression to retain the standard functionality?
Or is there a blindingly obvious easier way that I’m missing?
One idea is to create an array of matching result and adding PLC to them:
fiddle here: http://jsfiddle.net/xbZhr/8/