(
{
name,
placeholder,
type,
options,
step,
max,
min,
rows = '6',
checked,
multiple,
disabled,
required,
readOnly,
extraInputAttributes,
}: FormField,
value?: string | string[] | null,
)
| 88 | } |
| 89 | |
| 90 | function generateInputHtml( |
| 91 | { |
| 92 | name, |
| 93 | placeholder, |
| 94 | type, |
| 95 | options, |
| 96 | step, |
| 97 | max, |
| 98 | min, |
| 99 | rows = '6', |
| 100 | checked, |
| 101 | multiple, |
| 102 | disabled, |
| 103 | required, |
| 104 | readOnly, |
| 105 | extraInputAttributes, |
| 106 | }: FormField, |
| 107 | value?: string | string[] | null, |
| 108 | ) { |
| 109 | const stepAttribute = step && `step="${step}"`; |
| 110 | const maxAttribute = max && `max="${max}"`; |
| 111 | const minAttribute = min && `min="${min}"`; |
| 112 | const checkedAttribute = checked && type === 'checkbox' && value && 'checked'; |
| 113 | const multipleAttribute = multiple && 'multiple'; |
| 114 | const requiredAttritbute = required && 'required'; |
| 115 | const disabledAttribute = disabled && 'disabled'; |
| 116 | const readOnlyAttritubte = readOnly && 'readonly'; |
| 117 | |
| 118 | const additionalAttributes = [ |
| 119 | stepAttribute, |
| 120 | maxAttribute, |
| 121 | minAttribute, |
| 122 | checkedAttribute, |
| 123 | multipleAttribute, |
| 124 | requiredAttritbute, |
| 125 | disabledAttribute, |
| 126 | readOnlyAttritubte, |
| 127 | ].filter(Boolean).join(' '); |
| 128 | |
| 129 | if (type === 'select') { |
| 130 | return html` |
| 131 | <select |
| 132 | ${additionalAttributes} |
| 133 | ${extraInputAttributes || ''} |
| 134 | class="mt-1 input-field" |
| 135 | id="field_${name}" |
| 136 | name="${name}" |
| 137 | > |
| 138 | ${options |
| 139 | ?.map( |
| 140 | (option) => |
| 141 | html` |
| 142 | <option |
| 143 | value="${option.value}" |
| 144 | ${option.value === value || (multiple && (value || [])?.includes(option.value)) ? 'selected' : ''} |
| 145 | > |
| 146 | ${option.label} |
| 147 | </option> |
no test coverage detected