Add support for non-string options as well (numbers and booleans)

This commit is contained in:
Sipke Schoorstra 2021-04-28 22:23:19 +02:00
parent ce2e13d9e4
commit 90bc936f42

View file

@ -44,9 +44,9 @@ export class ElsaDropdownProperty {
single-line={true}>
<select id={fieldId} name={fieldName} onChange={e => this.onChange(e)} class="mt-1 block focus:ring-blue-500 focus:border-blue-500 w-full shadow-sm sm:max-w-xs sm:text-sm border-gray-300 rounded-md">
{options.map(option => {
const optionIsString = typeof(option) == 'string';
const value = optionIsString ? option : option.value;
const text = optionIsString ? option : option.text;
const optionIsObject = typeof (option) == 'object';
const value = optionIsObject ? option.value : option.toString();
const text = optionIsObject ? option.text : option.toString();
return <option value={value} selected={value === currentValue}>{text}</option>;
})}
</select>