Skip to content

Commit 71afccf

Browse files
authored
Modal input fixes
Signed-off-by: Faisal N <contact@faisaln.com>
1 parent be5da12 commit 71afccf

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/modules/ui.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ export function modal(options) {
4646
}
4747
const input = document.createElement((options.input.type === "select") ? "select" : "input");
4848
if (options.input.type !== "select") input.type = options.input.type || "text";
49-
if (options.input.options) {
49+
if ((options.input.type === "select") && options.input.multiple) input.multiple = options.input.multiple;
50+
if ((options.input.type === "select") && options.input.options) {
5051
options.input.options.forEach(option => {
5152
const optionElement = document.createElement("option");
52-
optionElement.value = option.value || option;
53-
optionElement.textContent = option.text || option;
53+
optionElement.value = option.value;
54+
optionElement.textContent = option.text;
55+
if (option.selected) optionElement.selected = true;
5456
input.appendChild(optionElement);
5557
});
5658
}
5759
input.placeholder = options.input.placeholder || "";
58-
input.value = options.input.defaultValue || "";
60+
if (options.input.defaultValue) input.value = options.input.defaultValue || "";
5961
input.className = "dialog-input";
6062
input.min = options.input.min || "";
6163
input.max = options.input.max || "";
@@ -73,16 +75,18 @@ export function modal(options) {
7375
}
7476
const inputElement = document.createElement((input.type === "select") ? "select" : "input");
7577
if (input.type !== "select") inputElement.type = input.type || "text";
76-
if (input.options) {
78+
if ((input.type === "select") && input.multiple) inputElement.multiple = input.multiple;
79+
if ((input.type === "select") && input.options) {
7780
input.options.forEach(option => {
7881
const optionElement = document.createElement("option");
79-
optionElement.value = option.value || option;
80-
optionElement.textContent = option.text || option;
82+
optionElement.value = option.value;
83+
optionElement.textContent = option.text;
84+
if (option.selected) optionElement.selected = true;
8185
inputElement.appendChild(optionElement);
8286
});
8387
}
8488
inputElement.placeholder = input.placeholder || "";
85-
inputElement.value = input.defaultValue || "";
89+
if (input.defaultValue) inputElement.value = input.defaultValue || "";
8690
inputElement.className = "dialog-input";
8791
inputElement.min = input.min || "";
8892
inputElement.max = input.max || "";

0 commit comments

Comments
 (0)