Add on change action to options field

This commit is contained in:
Andrew Kingston 2022-04-14 09:54:49 +01:00
parent bd7c009537
commit 02178d3f2b
1 changed files with 10 additions and 2 deletions

View File

@ -16,6 +16,7 @@
export let customOptions
export let autocomplete = false
export let direction = "vertical"
export let onChange
let fieldState
let fieldApi
@ -30,6 +31,13 @@
valueColumn,
customOptions
)
const handleChange = e => {
fieldApi.setValue(e.detail)
if (onChange) {
onChange({ value: e.detail })
}
}
</script>
<Field
@ -52,7 +60,7 @@
error={fieldState.error}
{options}
{placeholder}
on:change={e => fieldApi.setValue(e.detail)}
on:change={handleChange}
getOptionLabel={flatOptions ? x => x : x => x.label}
getOptionValue={flatOptions ? x => x : x => x.value}
{autocomplete}
@ -66,7 +74,7 @@
error={fieldState.error}
{options}
{direction}
on:change={e => fieldApi.setValue(e.detail)}
on:change={handleChange}
getOptionLabel={flatOptions ? x => x : x => x.label}
getOptionValue={flatOptions ? x => x : x => x.value}
/>