Fix options not appearing

The options only appeared when at least 2 letters were typed into the
input field as the event triggered before a value was set into the input
field. Using `keyup` instead of `keydown` delays the event after a
letter has been typed into it.
This commit is contained in:
Wolvan 2022-01-10 21:45:12 +01:00
parent 1ad2c8c1a0
commit 23445f7509

View file

@ -14,7 +14,7 @@
input.placeholder = "Enter your option here"; input.placeholder = "Enter your option here";
optionEl.appendChild(input); optionEl.appendChild(input);
input.addEventListener("keydown", () => { input.addEventListener("keyup", () => {
if (inputList.every(el => el.value) && pollOptionsAnchor) pollOptionsAnchor.appendChild(createPollOptionInput()); if (inputList.every(el => el.value) && pollOptionsAnchor) pollOptionsAnchor.appendChild(createPollOptionInput());
}); });
inputList.push(input); inputList.push(input);
@ -23,7 +23,7 @@
} }
pollOptionsAnchor.querySelectorAll(".poll-option input").forEach(el => { pollOptionsAnchor.querySelectorAll(".poll-option input").forEach(el => {
el.addEventListener("keydown", () => { el.addEventListener("keyup", () => {
if (inputList.every(el => el.value) && pollOptionsAnchor) pollOptionsAnchor.appendChild(createPollOptionInput()); if (inputList.every(el => el.value) && pollOptionsAnchor) pollOptionsAnchor.appendChild(createPollOptionInput());
}); });
inputList.push(el); inputList.push(el);