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 <noreply@anthropic.com>
This commit is contained in:
@@ -384,10 +384,18 @@ function renderFieldInput(field, fkOptions, isRequired) {
|
|||||||
} else if (field.type === 'datetime' || field.data_type.includes('date')) {
|
} else if (field.type === 'datetime' || field.data_type.includes('date')) {
|
||||||
const inputType = field.data_type === 'date' ? 'date' : 'datetime-local';
|
const inputType = field.data_type === 'date' ? 'date' : 'datetime-local';
|
||||||
const placeholder = isRequired ? '' : 'Оставьте пустым для NULL';
|
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 += `
|
html += `
|
||||||
<input type="${inputType}" id="field_${field.name}"
|
<input type="${inputType}" id="field_${field.name}"
|
||||||
style="width: 100%; padding: 8px; font-size: 14px; box-sizing: border-box; margin-top: 4px;"
|
style="width: 100%; padding: 8px; font-size: 14px; box-sizing: border-box; margin-top: 4px;"
|
||||||
placeholder="${escapeHtml(placeholder)}">
|
placeholder="${escapeHtml(placeholder)}"
|
||||||
|
value="${defaultValue}">
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
const placeholder = isRequired ? 'Введите значение' : 'Оставьте пустым для NULL';
|
const placeholder = isRequired ? 'Введите значение' : 'Оставьте пустым для NULL';
|
||||||
@@ -764,18 +772,21 @@ async function showEditModal(selectedRows) {
|
|||||||
const value = inputElement.value;
|
const value = inputElement.value;
|
||||||
const oldValue = field.valuesMatch ? field.commonValue : null;
|
const oldValue = field.valuesMatch ? field.commonValue : null;
|
||||||
|
|
||||||
// Проверить изменения
|
// Нормализовать старое значение для сравнения (для datetime обрезаем до даты)
|
||||||
const oldValueStr = oldValue !== null && oldValue !== undefined ? String(oldValue) : '';
|
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) : '';
|
const newValueStr = value !== null && value !== undefined ? String(value) : '';
|
||||||
|
|
||||||
|
// Включать поле в changes только если оно фактически изменено
|
||||||
if (oldValueStr !== newValueStr) {
|
if (oldValueStr !== newValueStr) {
|
||||||
hasChanges = true;
|
hasChanges = true;
|
||||||
}
|
if (value !== null && value !== '') {
|
||||||
|
changes[field.name] = convertFieldValue(value, field.type, field.data_type);
|
||||||
if (value !== null && value !== '') {
|
} else {
|
||||||
changes[field.name] = convertFieldValue(value, field.type, field.data_type);
|
changes[field.name] = null;
|
||||||
} else {
|
}
|
||||||
changes[field.name] = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user