Ultron/static/js/template_users/country_autocomplete.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-01-31 14:33:03 +01:00
$(document).ready(function() {
$('#id_country_related').autocomplete({
source: function(request, response) {
$.ajax({
url: '/country/lookup/?pattern=' + $('#id_country_related').val(),
dataType: "json",
success: function(data) {
if(data.length != 0) {
response($.map(data, function(item) {
return {
label: item.Label,
value: item.Label,
countryid: item.id
}
}))
} else {
response([{ label: 'No result found.', value: '' }]);
};
},
error: function (exception) {
console.log(exception);
}
});
},
minLength: 3,
select: function (event, ui) {
$($(this).data('ref')).val(ui.item.countryid);
}
});
});