I want to filter the autocomplete results based on the selected option in a select input.
sample json data:
[{"ContactId":"8590051631","ContactType":Company,"Name":"Test },{""ContactId":"8590049225","ContactType":Person,"Name":"TestName}]
here's my markup
<div>
<select class="type">
<option>Person</option>
<option>Company</option>
</select>
<input type="text" class="name" />
</div>
$('.name').autocomplete("http://services.mydomain.com/rest/ia/findcontact", {
dataType: 'jsonp',
extraParams: {
limit: '',
timestamp: '' }
},
parse: function(data) {
var items = data;
var parsed = [];
if (items != null || items != undefined) {
for (var i = 0; i < items.length; i++)
parsed[i] = { data: [items[i]], value: items[i].ContactId, result: [items[i].Name] };
}
return parsed;
},
formatMatch: function(d,i,t) {
alert($(this).parent().find(".type").val());
// do some filtering here?
}
});
It seems like I should use formatMatch option to filter the results but I can't get this to work. How do I filter the results based on the selected option value?