From fa4f4efb66fb185e863c5176c396c2980f363ac0 Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Mon, 10 Nov 2025 22:32:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=20Select2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Добавлены дополнительные обработчики событий (closing, keyup, change) - Добавлена проверка наличия search input элемента - Отключено кэширование для AJAX запросов - Добавлено форматирование параметров для debuggingтых - Убрана функция matcher для упрощения логики 🤖 Generated with Claude Code Co-Authored-By: Claude --- .../orders/templates/orders/order_form.html | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/myproject/orders/templates/orders/order_form.html b/myproject/orders/templates/orders/order_form.html index c417bf0..f8af74b 100644 --- a/myproject/orders/templates/orders/order_form.html +++ b/myproject/orders/templates/orders/order_form.html @@ -414,6 +414,8 @@ document.addEventListener('DOMContentLoaded', function() { placeholder: 'Начните вводить имя, телефон или email', minimumInputLength: 1, allowClear: true, + tags: false, + dropdownAutoWidth: false, ajax: { url: '{% url "customers:api-search-customers" %}', dataType: 'json', @@ -421,14 +423,21 @@ document.addEventListener('DOMContentLoaded', function() { quietMillis: 250, data: function(params) { console.log('AJAX DATA FUNCTION вызвана, поисковый запрос:', params.term); - return { + const queryData = { q: params.term || '', page: params.page || 1 }; + console.log('Отправляем данные:', queryData); + return queryData; }, - processResults: function(data) { + processResults: function(data, params) { console.log('AJAX RESPONSE получен:', data); console.log('Количество результатов:', data.results ? data.results.length : 0); + if (data.results) { + data.results.forEach(function(item, index) { + console.log('Результат ' + index + ':', item); + }); + } return { results: data.results || [], pagination: { @@ -436,7 +445,7 @@ document.addEventListener('DOMContentLoaded', function() { } }; }, - cache: true, + cache: false, error: function(jqXHR, textStatus, errorThrown) { console.error('AJAX ERROR при поиске клиента:', { status: textStatus, @@ -448,14 +457,7 @@ document.addEventListener('DOMContentLoaded', function() { }, templateResult: formatCustomerOption, templateSelection: formatCustomerSelection, - escapeMarkup: function(markup) { return markup; }, - matcher: function(params, data) { - // Позволяем все результаты, фильтрация на сервере - if ($.trim(params.term) === '') { - return null; - } - return data; - } + escapeMarkup: function(markup) { return markup; } }); console.log('Select2 инициализирован'); @@ -473,6 +475,28 @@ document.addEventListener('DOMContentLoaded', function() { console.log('SELECT2 SEARCHING - ищем, query:', e.params.term); }); + $customerSelect.on('select2:closing', function(e) { + console.log('SELECT2 CLOSING - закрытие dropdown'); + }); + + // Логируем изменение на уровне input + $customerSelect.on('keyup', function(e) { + console.log('KEYUP событие, текст:', $(this).val()); + }); + + $customerSelect.on('change', function(e) { + console.log('CHANGE событие, значение:', $(this).val()); + }); + + // Проверяем наличие input элемента внутри Select2 + setTimeout(function() { + const searchInput = $customerSelect.data('select2').$search || $customerSelect.data('select2').$searchContainer?.find('input'); + console.log('Select2 search input найден:', !!searchInput); + if (searchInput) { + console.log('Search input element:', searchInput); + } + }, 500); + // Форматирование опции в списке function formatCustomerOption(option) { console.log('formatCustomerOption вызвана для:', option);