I'm using jquery-ui autocomplete to validate some form inputs. I've got this code :
function addAutoComplete(beacon, url) {
$(document).ready(function(){
$('input' + beacon).autocomplete({
source: url,
minLength:3,
select: function(event, ui) {
var selectedObj = ui.item;
$(beacon+'_autocomplete_id').val(selectedObj.id);
return false;
},
change: function(event, ui){
if (ui.item == null){
$(beacon+'_autocomplete_id').val(0);
} else {
$(beacon+'_autocomplete_id').val(ui.item.id);
}
}
});
});
}
The goal is simple : associate the "id" value of the datas with an hidden field. When the user's input is not in the source, we put a "0". My problem is that when the user types everything and do not click or make use of the autocomplete, he could write a proper value but it would not be acknowleged as such.
I've seen how to avoid this problem if you store the source in a local array, for instance, but is there a w开发者_运维百科ay to do this with the source coming from the url ? In other terms, is there a property that allow me to manipulate the JSON I go from the url without having to code my callback function for the source ?
Thanks in advance !
Found a solution : using Scott González wonderful autoSelect option. Works perfectly, really great.
精彩评论