mirror of
https://github.com/Wolvan/poll.horse.git
synced 2024-11-28 23:27:58 +01:00
c00ea29b4f
If more than 3 options are written down, additional inputs will load in to allow more options. The maximum cap of options currently is set to 255 but can be configured in Config.ts. Likewise, the input length can also be controlled from there.
32 lines
No EOL
1.2 KiB
JavaScript
32 lines
No EOL
1.2 KiB
JavaScript
"use strict";
|
|
(() => {
|
|
const inputList = [];
|
|
const pollOptionsAnchor = document.querySelector(".poll-options");
|
|
|
|
function createPollOptionInput() {
|
|
if (inputList.length >= parseInt(MAX_POLL_OPTIONS)) return;
|
|
const optionEl = document.createElement("div");
|
|
optionEl.classList.add("poll-option");
|
|
const input = document.createElement("input");
|
|
input.type = "text";
|
|
input.maxLength = MAX_CHARACTER_LENGTH;
|
|
input.name = "poll-option";
|
|
input.placeholder = "Enter your option here";
|
|
optionEl.appendChild(input);
|
|
|
|
input.addEventListener("keydown", () => {
|
|
if (inputList.every(el => el.value) && pollOptionsAnchor) pollOptionsAnchor.appendChild(createPollOptionInput());
|
|
});
|
|
inputList.push(input);
|
|
|
|
return optionEl;
|
|
}
|
|
|
|
pollOptionsAnchor.querySelectorAll(".poll-option input").forEach(el => {
|
|
el.addEventListener("keydown", () => {
|
|
if (inputList.every(el => el.value) && pollOptionsAnchor) pollOptionsAnchor.appendChild(createPollOptionInput());
|
|
});
|
|
inputList.push(el);
|
|
});
|
|
return createPollOptionInput;
|
|
})(); |