0.0.36 upd autocomlitev2.js

This commit is contained in:
2023-07-21 18:33:34 +03:00
parent e377eecacf
commit 86bef4df2d
2 changed files with 35 additions and 232 deletions

View File

@@ -1,68 +1,48 @@
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});
get_address_point['ctrl_name'] = el.name;
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')
$.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){
//reset value
// if (ctrl_name.startsWith("from")){
// let fap_txt_cont = document.querySelector("#id_" + ctrl_name);
// let fap_cont = document.querySelector("#id_" + ctrl_name.slice(0, -4));
// fap_txt_cont.value = name;
// fap_cont.value = id;
// }
// else if (ctrl_name.startsWith("to")) {
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;
// }
// // from_address_point
// let fap_txt_cont = document.querySelector("#id_from_address_point_txt");
// let fap_cont = document.querySelector("#id_from_address_point");
// fap_txt_cont.value = name;
// fap_cont.value = id;
//to_address_point
}
}
function insertSearchList(data, ctrl_name) {
@@ -71,36 +51,10 @@ function insertSearchList(data, ctrl_name) {
let divs = data.res_search_list;
if (divs.length > 0) {
// let ac = document.querySelector("#id_from_address_point_txt");
input_list.classList.add("show");
input_list.innerHTML = divs;
} else {
input_list.classList.remove("show");
}
//
// if (ac.value.length > 2) {
// //
// // let res_data = data.data
// //
// // var divs = res_data.map(function(r, i) {
// // airport_name = "'"+r.iata_code + " - " + r.name+"'";
// //
// // return '<div onclick="selectItemAddrPoint('+ r.id+', '+ airport_name +')" class="autocomplete-result" data-index="'+ i +'" data-id="'+ r.id + '">'
// // + '<div><b>'+ r.iata_code +'</b> - '+ r.name +'</div>'
// // + '<div class="autocomplete-location">'+ r.city__name +', '+ r.city__country__name +'</div>'
// // + '</div>';
// // });
// //
// //
// //
// //
// //
// // // .html(divs.join(''))
// // // .attr('data-highlight', selectedIndex);
// //
// } else {
// numResults = 0;
// let divs = [];
//
// }
}