From f70cab8a6c639cb26f873ebc1ec36d0df4e8b979 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 14 Apr 2022 09:54:49 +0100 Subject: [PATCH] Add on change action to options field --- .../src/components/app/forms/OptionsField.svelte | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/app/forms/OptionsField.svelte b/packages/client/src/components/app/forms/OptionsField.svelte index 8140600e7e..c0f98ed827 100644 --- a/packages/client/src/components/app/forms/OptionsField.svelte +++ b/packages/client/src/components/app/forms/OptionsField.svelte @@ -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 }) + } + } 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} />