Add on change action to multi-select field

This commit is contained in:
Andrew Kingston 2022-04-14 09:51:41 +01:00
parent bd313c7204
commit bd7c009537
1 changed files with 9 additions and 3 deletions

View File

@ -14,6 +14,7 @@
export let valueColumn
export let customOptions
export let autocomplete = false
export let onChange
let fieldState
let fieldApi
@ -34,13 +35,18 @@
if (!values) {
return []
}
if (Array.isArray(values)) {
return values
}
return values.split(",").map(value => value.trim())
}
const handleChange = e => {
fieldApi.setValue(e.detail)
if (onChange) {
onChange({ value: e.detail })
}
}
</script>
<Field
@ -62,7 +68,7 @@
getOptionValue={flatOptions ? x => x : x => x.value}
id={fieldState.fieldId}
disabled={fieldState.disabled}
on:change={e => fieldApi.setValue(e.detail)}
on:change={handleChange}
{placeholder}
{options}
{autocomplete}