From ca1bbaa4f90dff9e679c44fcf7c0066115841e97 Mon Sep 17 00:00:00 2001 From: ArtemB Date: Wed, 9 Aug 2023 17:47:10 +0300 Subject: [PATCH] 0.0.81 fix multiple POST in seachTown function --- static/css/styles.css | 4 +- static/js/user_profile.js | 72 ++++++++++++----------- templates/blocks/profile/b_new_route.html | 1 + 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/static/css/styles.css b/static/css/styles.css index 3aa8dd0..f9cd2b3 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1084,7 +1084,7 @@ div.departure_arrival>div>input{ .input_list{ display: none; - width: 24%; + width: 390px; height: 200px; position: absolute; padding-top: 20px; @@ -1096,7 +1096,7 @@ div.departure_arrival>div>input{ } .input_list.show{ - display:block; + display:inline-block; } .input_list .hide{ diff --git a/static/js/user_profile.js b/static/js/user_profile.js index 2406e23..a9e7716 100644 --- a/static/js/user_profile.js +++ b/static/js/user_profile.js @@ -156,42 +156,48 @@ function confirmRemove(el) { 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){ - getNewMessageSession() - return insertSearchList(data, el.name + '_list') - }, - error: function (data){ - - console.log('Error') - + if(el.textLength>=3){ + let timer = null + if (timer) { + clearTimeout(timer); } - }); - }, 1500); + 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){ + getNewMessageSession() + return insertSearchList(data, el.name + '_list') + }, + error: function (data){ + + console.log('Error') + + } + }); + }, 1500); } + } + + + + diff --git a/templates/blocks/profile/b_new_route.html b/templates/blocks/profile/b_new_route.html index 720c0c0..971734d 100644 --- a/templates/blocks/profile/b_new_route.html +++ b/templates/blocks/profile/b_new_route.html @@ -80,6 +80,7 @@ onFocus="this.select()" autocomplete="off" type="text" + minlength="3" name="from_address_point_txt" class="from_address_point_txt" {% if form.fields.from_address_point.required %} required{% endif %}