Add on change action to multi-select field
This commit is contained in:
parent
bd313c7204
commit
bd7c009537
1 changed files with 9 additions and 3 deletions
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue