I´m using something like that:
var defaults = {
minChars: 2,
cacheLength: 1,
delay: 300,
max: 10,
id: null,
city: null,
jsonaddress: 'teste.php',
matchSubset: false,
selectFirst: false,
dataType: 'json',
extraParams: {
state: null,
county: null
},
parse: function(data){
var parsed = [];
data = data.name;
for (var i = 0; i < data.length; i++) {
parsed[parsed.length] = {
data: data[i],
value: data[i].displayName,
result: data[i].displayName
};
}
return parsed;
},
formatItem: function(item){
return item.displayName;
}
};
};
$(obj).unautocomplete().autocomplete(defaults.jsonaddress,
defaults ).attr('name', 'display_name').after('<input type="hidden"
name="user_id" class="ac_result">').result(function(e, data, formatted)
{
if (data) {
obj.next().val(data.id);
$.countyid = data.id;
}
else {
obj.next().val('');
}
Hi.. I´m using this function and its working great when I type a term
that returns a data from the server (adding a data.id to a input that
I wish to control). But if the search return no data the Result Event
doesn´t trigger. Is there a way to empty the hidden input value when
there´s no data from the server??
No comments:
Post a Comment