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);