Исправлен селектор формы в autosave.js
Заменил form[action*="edit"] на #order-form для корректной работы. Добавлено дополнительное логирование для отладки. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -25,15 +25,25 @@
|
||||
* Инициализация модуля автосохранения
|
||||
*/
|
||||
function init() {
|
||||
// Проверяем, что мы на странице редактирования черновика
|
||||
const orderForm = document.querySelector('form[action*="edit"]');
|
||||
console.log('[Autosave] Attempting to initialize...');
|
||||
|
||||
// Проверяем, что мы на странице редактирования
|
||||
const isEditPage = window.location.pathname.includes('/edit/');
|
||||
if (!isEditPage) {
|
||||
console.log('[Autosave] Not on edit page, exiting');
|
||||
return;
|
||||
}
|
||||
|
||||
const orderForm = document.getElementById('order-form');
|
||||
if (!orderForm) {
|
||||
console.log('[Autosave] Order form not found, exiting');
|
||||
return;
|
||||
}
|
||||
|
||||
// Получаем ID заказа из URL
|
||||
const urlMatch = window.location.pathname.match(/\/orders\/(\d+)\/edit\//);
|
||||
if (!urlMatch) {
|
||||
console.log('[Autosave] Could not extract order ID from URL, exiting');
|
||||
return;
|
||||
}
|
||||
orderId = urlMatch[1];
|
||||
@@ -41,6 +51,7 @@
|
||||
// Проверяем, является ли заказ черновиком
|
||||
isDraft = checkIfDraft();
|
||||
if (!isDraft) {
|
||||
console.log('[Autosave] Not a draft order, exiting');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,8 +69,9 @@
|
||||
*/
|
||||
function checkIfDraft() {
|
||||
// Проверяем через data-атрибут на форме
|
||||
const form = document.querySelector('form[action*="edit"]');
|
||||
const form = document.getElementById('order-form');
|
||||
if (form && form.dataset.isDraft === 'true') {
|
||||
console.log('[Autosave] Form has data-is-draft="true"');
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -151,11 +163,14 @@
|
||||
* Прикрепляет обработчики событий к полям формы
|
||||
*/
|
||||
function attachEventListeners() {
|
||||
const form = document.querySelector('form[action*="edit"]');
|
||||
const form = document.getElementById('order-form');
|
||||
if (!form) {
|
||||
console.log('[Autosave] Form not found in attachEventListeners');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[Autosave] Attaching event listeners to form fields');
|
||||
|
||||
// Слушаем изменения в основных полях заказа
|
||||
const fieldsToWatch = [
|
||||
'select[name="customer"]',
|
||||
@@ -306,7 +321,7 @@
|
||||
* Собирает данные формы для отправки
|
||||
*/
|
||||
function collectFormData() {
|
||||
const form = document.querySelector('form[action*="edit"]');
|
||||
const form = document.getElementById('order-form');
|
||||
const data = {};
|
||||
|
||||
// Основные поля заказа
|
||||
|
||||
Reference in New Issue
Block a user