Jarvis/static/js/template_users/routine_autocomplete.js

38 lines
1.2 KiB
JavaScript

$(document).ready(function() {
$('#id_routine_related').autocomplete({
source: function(request, response) {
$.ajax({
url: routine_lookup,
method: "POST",
data: {
pattern: $('#id_routine_related').val(),
csrfmiddlewaretoken: csrf_token
},
dataType: "json",
success: function(data) {
if(data.length != 0) {
response($.map(data, function(item) {
return {
label: item.label,
value: item.label,
routineid: 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.routineid);
}
});
});