Skip to content

Commit 339ff62

Browse files
committed
Fix tooltips on dynamically created buttons (Static DHCP lease table)
Dinamically created buttons were not showing tooltips because the event listener was created too early, before the buttons were created (only previuosly existing buttons would show a tooltip). Now, tooptip() function is called once, on the body element. This attaches an event listener to the body. Every dynamically created button will display the tooltip, without the need to call tooltip() function. We need to manually call .tooltip("hide"), to remove tooltips when buttons are clicked. Signed-off-by: RD WebDesign <[email protected]>
1 parent 3258eb5 commit 339ff62

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

scripts/js/settings-dhcp.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ let dhcpLeaesTable = null;
1313
const toasts = {};
1414

1515
// DHCP leases tooltips
16-
$(() => {
17-
$('[data-toggle="tooltip"]').tooltip({ html: true, container: "body" });
18-
});
16+
$("body").tooltip({ selector: '[data-toggle="tooltip"]', container: "body" });
1917

2018
function renderHostnameCLID(data, type) {
2119
// Display and search content
@@ -313,9 +311,9 @@ $(document).on("click", ".save-static-row", function () {
313311
hwaddr || ipaddr || hostname ? [hwaddr, ipaddr, hostname].filter(Boolean).join(",") : "";
314312
$("#dhcp-hosts").val(lines.join("\n"));
315313

316-
// On save remove the save button
317-
$(this).remove();
318-
// and remove highlight colors from all cells on this row
314+
// On save, hide the tooltip and remove the save button
315+
$(this).tooltip("hide").remove();
316+
// then remove highlight colors from all cells on this row
319317
$("td", row).removeClass("table-danger");
320318

321319
// Check if all rows were already saved (no rows are still being edited)
@@ -333,6 +331,8 @@ $(document).on("click", ".delete-static-row", function () {
333331
const lines = $("#dhcp-hosts").val().split(/\r?\n/v);
334332
lines.splice(rowIdx, 1);
335333
$("#dhcp-hosts").val(lines.join("\n"));
334+
// Hide the tooltip
335+
$(this).tooltip("hide");
336336
renderStaticDHCPTable();
337337
});
338338

@@ -342,6 +342,8 @@ $(document).on("click", ".add-static-row", function () {
342342
const lines = $("#dhcp-hosts").val().split(/\r?\n/v);
343343
lines.splice(rowIdx + 1, 0, "");
344344
$("#dhcp-hosts").val(lines.join("\n"));
345+
// Hide the tooltip
346+
$(this).tooltip("hide");
345347
renderStaticDHCPTable();
346348
// Focus the new row after render
347349
setTimeout(() => {

0 commit comments

Comments
 (0)