Улучшено логирование для отладки Select2
- Добавлены дополнительные обработчики событий (closing, keyup, change) - Добавлена проверка наличия search input элемента - Отключено кэширование для AJAX запросов - Добавлено форматирование параметров для debuggingтых - Убрана функция matcher для упрощения логики 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -414,6 +414,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
placeholder: 'Начните вводить имя, телефон или email',
|
placeholder: 'Начните вводить имя, телефон или email',
|
||||||
minimumInputLength: 1,
|
minimumInputLength: 1,
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
|
tags: false,
|
||||||
|
dropdownAutoWidth: false,
|
||||||
ajax: {
|
ajax: {
|
||||||
url: '{% url "customers:api-search-customers" %}',
|
url: '{% url "customers:api-search-customers" %}',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@@ -421,14 +423,21 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
quietMillis: 250,
|
quietMillis: 250,
|
||||||
data: function(params) {
|
data: function(params) {
|
||||||
console.log('AJAX DATA FUNCTION вызвана, поисковый запрос:', params.term);
|
console.log('AJAX DATA FUNCTION вызвана, поисковый запрос:', params.term);
|
||||||
return {
|
const queryData = {
|
||||||
q: params.term || '',
|
q: params.term || '',
|
||||||
page: params.page || 1
|
page: params.page || 1
|
||||||
};
|
};
|
||||||
|
console.log('Отправляем данные:', queryData);
|
||||||
|
return queryData;
|
||||||
},
|
},
|
||||||
processResults: function(data) {
|
processResults: function(data, params) {
|
||||||
console.log('AJAX RESPONSE получен:', data);
|
console.log('AJAX RESPONSE получен:', data);
|
||||||
console.log('Количество результатов:', data.results ? data.results.length : 0);
|
console.log('Количество результатов:', data.results ? data.results.length : 0);
|
||||||
|
if (data.results) {
|
||||||
|
data.results.forEach(function(item, index) {
|
||||||
|
console.log('Результат ' + index + ':', item);
|
||||||
|
});
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
results: data.results || [],
|
results: data.results || [],
|
||||||
pagination: {
|
pagination: {
|
||||||
@@ -436,7 +445,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
cache: true,
|
cache: false,
|
||||||
error: function(jqXHR, textStatus, errorThrown) {
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
console.error('AJAX ERROR при поиске клиента:', {
|
console.error('AJAX ERROR при поиске клиента:', {
|
||||||
status: textStatus,
|
status: textStatus,
|
||||||
@@ -448,14 +457,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
},
|
},
|
||||||
templateResult: formatCustomerOption,
|
templateResult: formatCustomerOption,
|
||||||
templateSelection: formatCustomerSelection,
|
templateSelection: formatCustomerSelection,
|
||||||
escapeMarkup: function(markup) { return markup; },
|
escapeMarkup: function(markup) { return markup; }
|
||||||
matcher: function(params, data) {
|
|
||||||
// Позволяем все результаты, фильтрация на сервере
|
|
||||||
if ($.trim(params.term) === '') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Select2 инициализирован');
|
console.log('Select2 инициализирован');
|
||||||
@@ -473,6 +475,28 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
console.log('SELECT2 SEARCHING - ищем, query:', e.params.term);
|
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) {
|
function formatCustomerOption(option) {
|
||||||
console.log('formatCustomerOption вызвана для:', option);
|
console.log('formatCustomerOption вызвана для:', option);
|
||||||
|
|||||||
Reference in New Issue
Block a user