Add on change action to multi-select field

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

View File

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