search: don't repeat same query on different events (#32044)
This commit is contained in:
parent
fcf8b9b195
commit
51c877099e
|
@ -13,6 +13,7 @@
|
|||
<script>
|
||||
$(function() {
|
||||
var timeout;
|
||||
var last_search = null;
|
||||
var $form = $('#combo-search-form-{{ cell.pk }}');
|
||||
var $input = $('#combo-search-input-{{ cell.pk }}');
|
||||
{% for search_service in cell.search_services %}
|
||||
|
@ -22,12 +23,15 @@ $(function() {
|
|||
{% endfor %}
|
||||
|
||||
function update() {
|
||||
var new_search = $input.val();
|
||||
if (new_search == last_search) return;
|
||||
last_search = new_search;
|
||||
$form.addClass('searching');
|
||||
var count = {{ cell.search_services|length }};
|
||||
{% for search_service in cell.search_services %}
|
||||
if (xhr_{{ forloop.counter }}) xhr_{{ forloop.counter }}.abort();
|
||||
xhr_{{ forloop.counter }} = $.get(url_{{ forloop.counter }},
|
||||
{'q': $input.val()},
|
||||
{'q': new_search},
|
||||
function (response) {
|
||||
xhr_{{ forloop.counter }} = null;
|
||||
$results_{{ forloop.counter }}.html(response);
|
||||
|
@ -49,6 +53,7 @@ $(function() {
|
|||
update(this);
|
||||
});
|
||||
$form.on('submit', function() {
|
||||
last_search = null; // make explicit submit search in all cases
|
||||
clearTimeout(timeout);
|
||||
update();
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue