diff --git a/myproject/orders/templates/orders/order_form.html b/myproject/orders/templates/orders/order_form.html index a726040..c417bf0 100644 --- a/myproject/orders/templates/orders/order_form.html +++ b/myproject/orders/templates/orders/order_form.html @@ -403,6 +403,10 @@ document.addEventListener('DOMContentLoaded', function() { // Django генерирует ID как id_customer для поля customer const $customerSelect = $('#id_customer'); + console.log('=== ИНИЦИАЛИЗАЦИЯ SELECT2 ДЛЯ CUSTOMER ==='); + console.log('Элемент найден:', $customerSelect.length > 0); + console.log('ID элемента:', $customerSelect.attr('id')); + $customerSelect.select2({ theme: 'bootstrap-5', width: '100%', @@ -416,12 +420,15 @@ document.addEventListener('DOMContentLoaded', function() { delay: 300, quietMillis: 250, data: function(params) { + console.log('AJAX DATA FUNCTION вызвана, поисковый запрос:', params.term); return { q: params.term || '', page: params.page || 1 }; }, processResults: function(data) { + console.log('AJAX RESPONSE получен:', data); + console.log('Количество результатов:', data.results ? data.results.length : 0); return { results: data.results || [], pagination: { @@ -430,8 +437,13 @@ document.addEventListener('DOMContentLoaded', function() { }; }, cache: true, - error: function() { - console.log('Ошибка при поиске клиента'); + error: function(jqXHR, textStatus, errorThrown) { + console.error('AJAX ERROR при поиске клиента:', { + status: textStatus, + error: errorThrown, + statusCode: jqXHR.status, + responseText: jqXHR.responseText + }); } }, templateResult: formatCustomerOption, @@ -446,16 +458,34 @@ document.addEventListener('DOMContentLoaded', function() { } }); + console.log('Select2 инициализирован'); + + // Логируем события + $customerSelect.on('select2:opening', function(e) { + console.log('SELECT2 OPENING - открытие dropdown'); + }); + + $customerSelect.on('select2:open', function(e) { + console.log('SELECT2 OPEN - dropdown открыт'); + }); + + $customerSelect.on('select2:searching', function(e) { + console.log('SELECT2 SEARCHING - ищем, query:', e.params.term); + }); + // Форматирование опции в списке function formatCustomerOption(option) { + console.log('formatCustomerOption вызвана для:', option); if (!option.id) { return option.text; } if (option.is_create_option) { + console.log('Форматируем опцию создания клиента'); return '
' + option.text + '
'; } + console.log('Форматируем опцию клиента:', option.name); let html = '
'; html += '' + option.name + ''; if (option.phone) { @@ -470,6 +500,7 @@ document.addEventListener('DOMContentLoaded', function() { // Форматирование выбранного значения function formatCustomerSelection(option) { + console.log('formatCustomerSelection вызвана для:', option); if (!option.id) { return option.text; } @@ -482,12 +513,16 @@ document.addEventListener('DOMContentLoaded', function() { // Обработка выбора в Select2 $customerSelect.on('select2:select', function(e) { const data = e.params.data; + console.log('SELECT2:SELECT - выбран элемент:', data); if (data.is_create_option) { + console.log('Это опция создания клиента, открываем модальное окно'); // Очищаем select2 $(this).val(null).trigger('change'); // Открываем модальное окно для создания клиента openCreateCustomerModal(data.search_text); + } else { + console.log('Выбран существующий клиент:', data.name); } });