Autocomplete with remote JSON: how to handle a wrong selection
Hi,
Im using a remote-cache method for autocomplete and then i change a hidden field that contais the ID field:
<script>
$(function() {
var cache = {},
lastXhr;
$( "#txt_birds" ).autocomplete({
minLength: 1,
select: function(event, ui){
$("#sel_birds").val(ui.item.id);
},
source: function( request, response ) {
var term = request.term;
if ( term in cache ) {
$("#txt_birds").removeClass( "ui-autocomplete-loading" );
response( cache[ term ] );
return;
}
lastXhr = $.getJSON( "getbirds.php", request, function( data, status, xhr ) {
cache[ term ] = data;
if ( xhr === lastXhr ) {
$("#txt_birds").removeClass( "ui-autocomplete-loading" );
response( data );
}
});
}
});
});
</script>
I want to handle when a user type in Autocomplete some value that is not in the JSON response, or if a get a null response.
My idea is to clean the selection if result from JSOn is null and not allow to the user submit the form.
I dont want to simulate a combobox.
could i get some help?