1
0
Fork 0
mirror of synced 2024-09-12 07:27:20 +12:00

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

View file

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