Skip to content

Commit e43c4c6

Browse files
committed
Disable the textarea during table editing to prevent loss of unsaved data
If enabled, the textarea can be edited, which triggers a table rewrite, resulting in the loss of all unsaved changes made to the table rows. This commit keeps the textarea disabled until all edited rows are saved. Signed-off-by: RD WebDesign <[email protected]>
1 parent 34b4228 commit e43c4c6

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

scripts/js/settings-dhcp.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,18 +313,20 @@ $(document).on("click", ".save-static-row", function () {
313313
hwaddr || ipaddr || hostname ? [hwaddr, ipaddr, hostname].filter(Boolean).join(",") : "";
314314
$("#dhcp-hosts").val(lines.join("\n"));
315315

316-
// On save, re-enable all buttons, except from all rows currently being edited, ...
317-
$("#StaticDHCPTable tbody tr:not(:has(+ tr.edit-hint-row), .edit-hint-row) button").prop(
318-
"disabled",
319-
false,
320-
);
321-
// ... then enable the buttons on the current row, ...
322-
row.find(".delete-static-row, .add-static-row").prop("disabled", false);
323-
// ... remove highlight colors from all cells on this row ...
324-
$("td", row).removeClass("table-danger");
325-
// ... and remove the save button and the hint
316+
// On save remove the save button and the hint
326317
$(this).remove();
327318
row.next(".edit-hint-row").remove();
319+
// and remove highlight colors from all cells on this row
320+
$("td", row).removeClass("table-danger");
321+
322+
// Check if all rows were already saved (no rows are still being edited)
323+
if ($("#StaticDHCPTable .edit-hint-row").length == 0) {
324+
// Re-enable all table buttons
325+
$("#StaticDHCPTable button").prop("disabled", false);
326+
// and re-enable the textarea
327+
$("#dhcp-hosts").prop("disabled", false);
328+
$("#dhcp-hosts").prop("title", "");
329+
}
328330
});
329331

330332
// Delete button for each row removes that line from the textarea and updates the table
@@ -386,8 +388,15 @@ $(document).on("focus input", "#StaticDHCPTable td[contenteditable]", function (
386388
)
387389
);
388390

389-
row.next(".edit-hint-row").remove(); // Remove any existing hint
390-
row.after(hintRow); // Add the created hint
391+
// Disable the textarea to avoid losing unsaved changes to the table
392+
$("#dhcp-hosts").prop("disabled", true);
393+
$("#dhcp-hosts").prop("title", "Disabled.\nConfirm all changes above to enable this field");
394+
395+
// Remove any previously existing hint
396+
row.next(".edit-hint-row").remove();
397+
398+
// Add the created hint
399+
row.after(hintRow);
391400
}
392401
});
393402

0 commit comments

Comments
 (0)