Skip to content

Commit

Permalink
fix edit button with removeEventlistener
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicezki committed Oct 9, 2023
1 parent bb1b76f commit fe13277
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions main-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,25 +1090,29 @@ class ARMMane{
this.elements["form"]["cconf_03"].value = element.getAttribute("data-value");
this.showElement("ui", "cconfbox");

// Add event listener to save button
this.elements["btn"]["cconf_btn_save"].addEventListener("click", () => {
element.setAttribute("data-type", this.elements["form"]["cconf_01"].value);
element.setAttribute("data-device", this.elements["form"]["cconf_02"].value);
element.setAttribute("data-value", this.elements["form"]["cconf_03"].value);
this.consoleLog("「ARMMANE」 Command changed to " + this.elements["form"]["cconf_01"].value + "(" + this.elements["form"]["cconf_02"].value + "," + this.elements["form"]["cconf_03"].value + ");");
element.querySelector(".cmd-text > div > h2").textContent = this.elements["form"]["cconf_01"].value + "(" + this.elements["form"]["cconf_02"].value + "," + this.elements["form"]["cconf_03"].value + ");";
this.consoleLog("「ARMMANE」 Command changed to element " + element.id + " with value " + element.getAttribute("data-type") + "(" + element.getAttribute("data-device") + "," + element.getAttribute("data-value") + ");");
this.hideElement("ui", "cconfbox");
// Remove event listener
this.elements["btn"]["cconf_btn_save"].removeEventListener("click", () => {});
});
// Define the event handlers as named functions
const saveButtonHandler = () => {
element.setAttribute("data-type", this.elements["form"]["cconf_01"].value);
element.setAttribute("data-device", this.elements["form"]["cconf_02"].value);
element.setAttribute("data-value", this.elements["form"]["cconf_03"].value);
this.consoleLog("「ARMMANE」 Command changed to " + this.elements["form"]["cconf_01"].value + "(" + this.elements["form"]["cconf_02"].value + "," + this.elements["form"]["cconf_03"].value + ");");
element.querySelector(".cmd-text > div > h2").textContent = this.elements["form"]["cconf_01"].value + "(" + this.elements["form"]["cconf_02"].value + "," + this.elements["form"]["cconf_03"].value + ");";
this.consoleLog("「ARMMANE」 Command changed to element " + element.id + " with value " + element.getAttribute("data-type") + "(" + element.getAttribute("data-device") + "," + element.getAttribute("data-value") + ");");
this.hideElement("ui", "cconfbox");
this.elements["btn"]["cconf_btn_save"].removeEventListener("click", saveButtonHandler);
};

const cancelButtonHandler = () => {
this.hideElement("ui", "cconfbox");
this.elements["btn"]["cconf_btn_cancel"].removeEventListener("click", cancelButtonHandler);
};

// Add event listener to save button
this.elements["btn"]["cconf_btn_save"].addEventListener("click", saveButtonHandler);

// Add event listener to cancel button
this.elements["btn"]["cconf_btn_cancel"].addEventListener("click", cancelButtonHandler);

// Add event listener to cancel button
this.elements["btn"]["cconf_btn_cancel"].addEventListener("click", () => {
this.hideElement("ui", "cconfbox");
// Remove event listener
this.elements["btn"]["cconf_btn_cancel"].removeEventListener("click", () => {});
});
}

createPresetButton(){
Expand Down

0 comments on commit fe13277

Please sign in to comment.