60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
function searchTown(el){
|
|
let timer = null
|
|
if (timer) {
|
|
clearTimeout(timer);
|
|
}
|
|
timer = setTimeout(function(){
|
|
|
|
timer = null;
|
|
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});
|
|
get_address_point['ctrl_name'] = el.name;
|
|
|
|
$.ajax({
|
|
headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() },
|
|
url: '/ru/reference_data/get_address_point/',
|
|
type: "POST",
|
|
// async: true,
|
|
cache: false,
|
|
processData: false,
|
|
contentType: false,
|
|
// enctype: 'json',
|
|
data: JSON.stringify(get_address_point),
|
|
success: function(data){
|
|
return insertSearchList(data, el.name + '_list')
|
|
},
|
|
error: function (data){
|
|
console.log('Error')
|
|
|
|
}
|
|
});
|
|
}, 1000);
|
|
}
|
|
|
|
|
|
|
|
|
|
function selectItemAddrPoint(id, name, ctrl_name){
|
|
|
|
let tap_txt_cont = document.querySelector("#id_" + ctrl_name);
|
|
tap_txt_cont.value = name;
|
|
let tap_cont = document.querySelector("#id_" + ctrl_name.slice(0, -4));
|
|
tap_cont.value = id;
|
|
}
|
|
|
|
|
|
function insertSearchList(data, ctrl_name) {
|
|
|
|
let input_list = document.getElementsByName(ctrl_name)[0];
|
|
let divs = data.res_search_list;
|
|
|
|
if (divs.length > 0) {
|
|
input_list.classList.add("show");
|
|
input_list.innerHTML = divs;
|
|
} else {
|
|
input_list.classList.remove("show");
|
|
}
|
|
|
|
} |