I'd like to give a "No matches" message on a jquery autocomplete when the result is empty.
A partial answer was given here, but it doesn't explain exactly how to show the "No matches" result in the autocomplete dropdown.
UPDATE: Here is my code based on the current answers..
HTML:
<input type="text" name="myAutocomplete" id="myAutocomplete">
jQuery:
$("#myAutocomplete").autocomplete("ajax.php", {
selectFirst: false,
resultsClass: 'my_results_class',
parse: function(data) {
if (!data || data.length == 0) {
$('#myAutocomplete option').val('No Matches');
}
},
focus: function(event, ui) {
if($(ui.item).val() == 'No Matches')
$(ui.item).disable();
},
select: function(event, ui){
if($(ui.item).val() == 'No Matches')
return false;
}
});