From 23445f75099cfefb87d0bf1c0ca5a78cbf3743bb Mon Sep 17 00:00:00 2001 From: Wolvan Date: Mon, 10 Jan 2022 21:45:12 +0100 Subject: [PATCH] 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. --- frontend/static/js/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/static/js/index.js b/frontend/static/js/index.js index 5fae1fd..a6d48e9 100644 --- a/frontend/static/js/index.js +++ b/frontend/static/js/index.js @@ -14,7 +14,7 @@ input.placeholder = "Enter your option here"; optionEl.appendChild(input); - input.addEventListener("keydown", () => { + input.addEventListener("keyup", () => { if (inputList.every(el => el.value) && pollOptionsAnchor) pollOptionsAnchor.appendChild(createPollOptionInput()); }); inputList.push(input); @@ -23,7 +23,7 @@ } pollOptionsAnchor.querySelectorAll(".poll-option input").forEach(el => { - el.addEventListener("keydown", () => { + el.addEventListener("keyup", () => { if (inputList.every(el => el.value) && pollOptionsAnchor) pollOptionsAnchor.appendChild(createPollOptionInput()); }); inputList.push(el);