From a102e54c8b1a13894c967bf271a2ae80e2247489 Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Wed, 11 Mar 2026 15:28:42 +0300 Subject: [PATCH] Fix bulk edit and insert date field handling - Bulk edit: only include changed fields in update payload so unchanged date fields are not overwritten with null - Bulk edit: normalize datetime oldValue to date-only for correct comparison - Insert form: pre-fill date/datetime fields with today's date by default Co-Authored-By: Claude Sonnet 4.6 --- public/js/operations.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/public/js/operations.js b/public/js/operations.js index 8480a42..058e2c5 100644 --- a/public/js/operations.js +++ b/public/js/operations.js @@ -384,10 +384,18 @@ function renderFieldInput(field, fkOptions, isRequired) { } else if (field.type === 'datetime' || field.data_type.includes('date')) { const inputType = field.data_type === 'date' ? 'date' : 'datetime-local'; const placeholder = isRequired ? '' : 'Оставьте пустым для NULL'; + const today = new Date(); + const todayISO = today.getFullYear() + '-' + + String(today.getMonth() + 1).padStart(2, '0') + '-' + + String(today.getDate()).padStart(2, '0'); + const defaultValue = field.data_type === 'date' + ? todayISO + : todayISO + 'T' + String(today.getHours()).padStart(2, '0') + ':' + String(today.getMinutes()).padStart(2, '0'); html += ` + placeholder="${escapeHtml(placeholder)}" + value="${defaultValue}"> `; } else { const placeholder = isRequired ? 'Введите значение' : 'Оставьте пустым для NULL'; @@ -764,18 +772,21 @@ async function showEditModal(selectedRows) { const value = inputElement.value; const oldValue = field.valuesMatch ? field.commonValue : null; - // Проверить изменения - const oldValueStr = oldValue !== null && oldValue !== undefined ? String(oldValue) : ''; + // Нормализовать старое значение для сравнения (для datetime обрезаем до даты) + let oldValueStr = oldValue !== null && oldValue !== undefined ? String(oldValue) : ''; + if ((field.type === 'datetime' || field.data_type.includes('date')) && oldValueStr) { + oldValueStr = oldValueStr.split('T')[0]; + } const newValueStr = value !== null && value !== undefined ? String(value) : ''; + // Включать поле в changes только если оно фактически изменено if (oldValueStr !== newValueStr) { hasChanges = true; - } - - if (value !== null && value !== '') { - changes[field.name] = convertFieldValue(value, field.type, field.data_type); - } else { - changes[field.name] = null; + if (value !== null && value !== '') { + changes[field.name] = convertFieldValue(value, field.type, field.data_type); + } else { + changes[field.name] = null; + } } }