cannot submit device edits without changing input values
This commit is contained in:
parent
4bf539963a
commit
fd1b4ace5d
@ -6,11 +6,18 @@ getDevices().then(res => {
|
|||||||
buildTable(res)
|
buildTable(res)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
let selectedId = null; // Store the selected referenceId
|
let selectedId = null; // Store the selected referenceId
|
||||||
const nameInput = document.getElementById("name");
|
const nameInput = document.getElementById("name");
|
||||||
const tempHighInput = document.getElementById("tempHigh");
|
const tempHighInput = document.getElementById("tempHigh");
|
||||||
const tempLowInput = document.getElementById("tempLow");
|
const tempLowInput = document.getElementById("tempLow");
|
||||||
|
|
||||||
|
const editbtn = document.getElementById("editbtn");
|
||||||
|
|
||||||
|
var name;
|
||||||
|
var tempHigh;
|
||||||
|
var tempLow;
|
||||||
|
|
||||||
function buildTable(data) {
|
function buildTable(data) {
|
||||||
var table = document.getElementById("deviceTable");
|
var table = document.getElementById("deviceTable");
|
||||||
table.innerHTML = ""; // Clear existing rows before adding new ones
|
table.innerHTML = ""; // Clear existing rows before adding new ones
|
||||||
@ -40,17 +47,26 @@ function buildTable(data) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Attach click event to all trash buttons
|
// Attach click event to all trash buttons
|
||||||
document.querySelectorAll(".editIconbtn").forEach((btn) => {
|
document.querySelectorAll(".editIconbtn").forEach((btn) => {
|
||||||
btn.onclick = function () {
|
btn.onclick = function () {
|
||||||
selectedId = this.getAttribute("data-id"); // Store referenceId
|
selectedId = this.getAttribute("data-id"); // Store referenceId
|
||||||
// document.getElementById("editDeviceHeader").innerHTML = `Edit Device ${this.getAttribute("data-referenceId")}`;
|
document.getElementById("editDeviceHeader").innerHTML = `Edit Device ${this.getAttribute("data-referenceId")}`;
|
||||||
nameInput.value = this.getAttribute("data-name");
|
nameInput.value = this.getAttribute("data-name");
|
||||||
tempHighInput.value = this.getAttribute("data-tempHigh");
|
tempHighInput.value = this.getAttribute("data-tempHigh");
|
||||||
tempLowInput.value = this.getAttribute("data-tempLow");
|
tempLowInput.value = this.getAttribute("data-tempLow");
|
||||||
|
name = nameInput.value;
|
||||||
|
tempHigh = tempHighInput.value;
|
||||||
|
tempLow = tempLowInput.value;
|
||||||
|
editbtn.disabled = true;
|
||||||
document.getElementById("editModal").style.display = "block";
|
document.getElementById("editModal").style.display = "block";
|
||||||
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("addDevice").onclick = () => {
|
document.getElementById("addDevice").onclick = () => {
|
||||||
@ -67,6 +83,19 @@ document.querySelectorAll(".cancelbtn").forEach(button => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const checkForChanges = () => {
|
||||||
|
if (nameInput.value !== name || tempHighInput.value !== tempHigh || tempLowInput.value !== tempLow) {
|
||||||
|
editbtn.disabled = false; // Enable button if changes were made
|
||||||
|
} else {
|
||||||
|
editbtn.disabled = true; // Disable button if no changes
|
||||||
|
}
|
||||||
|
};
|
||||||
|
nameInput.addEventListener("input", checkForChanges);
|
||||||
|
tempHighInput.addEventListener("input", checkForChanges);
|
||||||
|
tempLowInput.addEventListener("input", checkForChanges);
|
||||||
|
|
||||||
// Delete button logic
|
// Delete button logic
|
||||||
document.getElementById("deletebtn").onclick = () => {
|
document.getElementById("deletebtn").onclick = () => {
|
||||||
if (selectedId) {
|
if (selectedId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user