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