0.0.22 autocomlitev2.js
This commit is contained in:
53
static/js/autocomlitev2.js
Normal file
53
static/js/autocomlitev2.js
Normal file
@@ -0,0 +1,53 @@
|
||||
function searchTown(el){
|
||||
let form = el.form;
|
||||
let type_transport = form['type_transport'].value;
|
||||
let search_str = el.value;
|
||||
let get_address_point = new Object({type_transport, search_str})
|
||||
|
||||
|
||||
$.ajax({
|
||||
headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() },
|
||||
url: '/reference_data/get_address_point/',
|
||||
type: "POST",
|
||||
// async: true,
|
||||
cache: false,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
// enctype: 'json',
|
||||
data: get_address_point,
|
||||
success: function(data){
|
||||
return data;
|
||||
},
|
||||
error: function (data){
|
||||
console.log('++')
|
||||
// document.querySelector(".button_register").innerHTML = data.responseJSON.html
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function search(e) {
|
||||
|
||||
let ac = document.querySelector("#id_from_country")
|
||||
|
||||
if (ac.value.length > 0) {
|
||||
|
||||
let results = searchTown(ac);
|
||||
|
||||
var divs = results.map()(function(r, i) {
|
||||
return '<div class="autocomplete-result" data-index="'+ i +'">'
|
||||
+ '<div><b>'+ r.iata +'</b> - '+ r.name +'</div>'
|
||||
+ '<div class="autocomplete-location">'+ r.city +', '+ r.country +'</div>'
|
||||
+ '</div>';
|
||||
});
|
||||
|
||||
selectedIndex = -1;
|
||||
list.html(divs.join(''))
|
||||
.attr('data-highlight', selectedIndex);
|
||||
|
||||
} else {
|
||||
numResults = 0;
|
||||
list.empty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user