Исправлен селектор формы в 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() {
|
function init() {
|
||||||
// Проверяем, что мы на странице редактирования черновика
|
console.log('[Autosave] Attempting to initialize...');
|
||||||
const orderForm = document.querySelector('form[action*="edit"]');
|
|
||||||
|
// Проверяем, что мы на странице редактирования
|
||||||
|
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) {
|
if (!orderForm) {
|
||||||
|
console.log('[Autosave] Order form not found, exiting');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Получаем ID заказа из URL
|
// Получаем ID заказа из URL
|
||||||
const urlMatch = window.location.pathname.match(/\/orders\/(\d+)\/edit\//);
|
const urlMatch = window.location.pathname.match(/\/orders\/(\d+)\/edit\//);
|
||||||
if (!urlMatch) {
|
if (!urlMatch) {
|
||||||
|
console.log('[Autosave] Could not extract order ID from URL, exiting');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
orderId = urlMatch[1];
|
orderId = urlMatch[1];
|
||||||
@@ -41,6 +51,7 @@
|
|||||||
// Проверяем, является ли заказ черновиком
|
// Проверяем, является ли заказ черновиком
|
||||||
isDraft = checkIfDraft();
|
isDraft = checkIfDraft();
|
||||||
if (!isDraft) {
|
if (!isDraft) {
|
||||||
|
console.log('[Autosave] Not a draft order, exiting');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,8 +69,9 @@
|
|||||||
*/
|
*/
|
||||||
function checkIfDraft() {
|
function checkIfDraft() {
|
||||||
// Проверяем через data-атрибут на форме
|
// Проверяем через data-атрибут на форме
|
||||||
const form = document.querySelector('form[action*="edit"]');
|
const form = document.getElementById('order-form');
|
||||||
if (form && form.dataset.isDraft === 'true') {
|
if (form && form.dataset.isDraft === 'true') {
|
||||||
|
console.log('[Autosave] Form has data-is-draft="true"');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,11 +163,14 @@
|
|||||||
* Прикрепляет обработчики событий к полям формы
|
* Прикрепляет обработчики событий к полям формы
|
||||||
*/
|
*/
|
||||||
function attachEventListeners() {
|
function attachEventListeners() {
|
||||||
const form = document.querySelector('form[action*="edit"]');
|
const form = document.getElementById('order-form');
|
||||||
if (!form) {
|
if (!form) {
|
||||||
|
console.log('[Autosave] Form not found in attachEventListeners');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[Autosave] Attaching event listeners to form fields');
|
||||||
|
|
||||||
// Слушаем изменения в основных полях заказа
|
// Слушаем изменения в основных полях заказа
|
||||||
const fieldsToWatch = [
|
const fieldsToWatch = [
|
||||||
'select[name="customer"]',
|
'select[name="customer"]',
|
||||||
@@ -306,7 +321,7 @@
|
|||||||
* Собирает данные формы для отправки
|
* Собирает данные формы для отправки
|
||||||
*/
|
*/
|
||||||
function collectFormData() {
|
function collectFormData() {
|
||||||
const form = document.querySelector('form[action*="edit"]');
|
const form = document.getElementById('order-form');
|
||||||
const data = {};
|
const data = {};
|
||||||
|
|
||||||
// Основные поля заказа
|
// Основные поля заказа
|
||||||
|
|||||||
Reference in New Issue
Block a user