Files
account_store/static/js/autocomlite.js
2023-07-29 17:50:32 +03:00

95 lines
2.5 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 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 showSearchList() {
let input_list = document.getElementsByClassName('input_list');
if(input_list.classList.contains('show')){
input_list.classList.add("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')
}
// }
}
// function hideErrorMsg(el) {
// let hide_element = document.querySelector()
// if(el.value !== 0){
// hide_element.classList.add('hide')
// }
//
// }