Hi I'm trying to get the jQuery UI autocomplete widget to work so that it searches for matches from multiple attributes of my array but something does not work in my code. For the moment
The idea it is if I type "coupe", response will be "Porsche, Audi, Mercedes". In the same way I will able to type '911' and receive as response "Porsche". Thanks for your help.
$(function() {
var cars =
[
{ "constructor" : "BMW",
"model": "Z3",
"type": "cabrio" },
{ "constructor" : "Porsche",
"model": "911",
"type": "coupe" },
{ "constructor" : "Audi",
"model": "A3",
"type": "coupe" },
{ "constructor" : "Mercedes",
"model": "SL500",
"type": "coupe" }
];
$("#quickFind").autocomplete({
source: function(request, response){
var matcher = new RegExp( $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( cars, function( value ) {
return matcher.test(value.constructor) || matcher.test(value.model) || matcher.test(value.type);
}));
}
});
});