0.0.43
This commit is contained in:
78
static/js/autocomlite.js
Normal file
78
static/js/autocomlite.js
Normal file
@@ -0,0 +1,78 @@
|
||||
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 input_list = document.getElementsByName(ctrl_name + '_list')[0];
|
||||
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;
|
||||
|
||||
input_list.classList.remove('show');
|
||||
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onblurInputField(event,el){
|
||||
|
||||
// if(el.classList.contains("from_country_container")){
|
||||
let search_list = document.getElementsByName(el.name + '_list')[0];
|
||||
let parent_event = $(event.explicitOriginalTarget).parents('.input_list' );
|
||||
if(!parent_event || parent_event[0] !== search_list){
|
||||
|
||||
search_list.classList.remove('show')
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user