Skip to content

Commit

Permalink
Fixed a bug with user defined variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluestonex63 committed Sep 12, 2024
1 parent 53152d0 commit 9cb40f1
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,20 @@ let varc = (vari, lvls, cats, masterdiv) => {
form.appendChild(document.createElement("br"))
form.appendChild(inp)
if (appvar["user-defined"]) {
if ((inp.nextElementSibling == null || inp.nextElementSibling.type != "text") && inp.value == 1) {
let definedvar = document.createElement("input")
definedvar.id = "definedvar"
definedvar.type = "text"
inp.insertAdjacentElement("afterend", definedvar)
}
inp.addEventListener("change", () => {
if (masterdiv.querySelector("#definedvar") == null && inp.value == 1) {
if ((inp.nextElementSibling == null || inp.nextElementSibling.type != "text") && inp.value == 1) {
let definedvar = document.createElement("input")
definedvar.id = "definedvar"
definedvar.type = "text"
form.appendChild(definedvar)
} else if (masterdiv.querySelector("#definedvar") != null && inp.value != 1) {
form.removeChild(masterdiv.querySelector("#definedvar"))
inp.insertAdjacentElement("afterend", definedvar)
} else if (inp.nextElementSibling.type == "text" && inp.value != 1) {
form.removeChild(inp.nextElementSibling)
}
})
}
Expand Down Expand Up @@ -511,14 +517,20 @@ button.addEventListener("click", async function() {
form.appendChild(document.createElement("br"))
form.appendChild(inp)
if (appvar["user-defined"]) {
if ((inp.nextElementSibling == null || inp.nextElementSibling.type != "text") && inp.value == 1) {
let definedvar = document.createElement("input")
definedvar.id = "defdefinedvar"
definedvar.type = "text"
inp.insertAdjacentElement("afterend", definedvar)
}
inp.addEventListener("change", () => {
if (document.querySelector("#defdefinedvar") == null && inp.value == 1) {
if ((inp.nextElementSibling == null || inp.nextElementSibling.type != "text") && inp.value == 1) {
let definedvar = document.createElement("input")
definedvar.id = "defdefinedvar"
definedvar.type = "text"
form.appendChild(definedvar)
} else if (document.querySelector("#defdefinedvar") != null && inp.value != 1) {
form.removeChild(document.querySelector("#defdefinedvar"))
inp.insertAdjacentElement("afterend", definedvar)
} else if (inp.nextElementSibling.type == "text" && inp.value != 1) {
form.removeChild(inp.nextElementSibling)
}
})
}
Expand Down

0 comments on commit 9cb40f1

Please sign in to comment.