* Creates an input * @param {Input} input Input object * @param {boolean} group Whether the input is part of a group * @returns {HTMLInputElement|HTMLTextAreaElement}
(input, group = false)
| 196 | * @returns {HTMLInputElement|HTMLTextAreaElement} |
| 197 | */ |
| 198 | function createInput(input, group = false) { |
| 199 | const { |
| 200 | id, |
| 201 | required, |
| 202 | type, |
| 203 | match, |
| 204 | value, |
| 205 | placeholder, |
| 206 | hints, |
| 207 | name, |
| 208 | disabled, |
| 209 | onclick, |
| 210 | onchange, |
| 211 | readOnly, |
| 212 | autofocus, |
| 213 | hidden, |
| 214 | } = input; |
| 215 | |
| 216 | const inputType = type === "textarea" ? "textarea" : "input"; |
| 217 | let _type = type === "filename" ? "text" : type || "text"; |
| 218 | |
| 219 | let $input; |
| 220 | |
| 221 | if (_type === "checkbox" || _type === "radio") { |
| 222 | $input = Checkbox(placeholder, value, name, id, type); |
| 223 | |
| 224 | if (!group) { |
| 225 | $input.style.marginTop = "1rem"; |
| 226 | } |
| 227 | } else { |
| 228 | $input = tag(inputType, { |
| 229 | id, |
| 230 | placeholder, |
| 231 | value: value, |
| 232 | className: "input", |
| 233 | isRequired: required, |
| 234 | readOnly, |
| 235 | autofocus, |
| 236 | hidden, |
| 237 | }); |
| 238 | |
| 239 | if (value) { |
| 240 | setTimeout(() => { |
| 241 | $input.scrollLeft = $input.scrollWidth; |
| 242 | }, 0); |
| 243 | } |
| 244 | |
| 245 | if (disabled) $input.disabled = true; |
| 246 | if (hints) inputhints($input, hints); |
| 247 | |
| 248 | if (inputType === "textarea") { |
| 249 | $input.rows = 1; |
| 250 | $input.inputMode = _type; |
| 251 | autosize($input); |
| 252 | } else { |
| 253 | $input.type = _type; |
| 254 | } |
| 255 |
no test coverage detected