From d2ffc2e920ebe2909f25fe7c737544bac736f40a Mon Sep 17 00:00:00 2001 From: Bastiaan Terhorst Date: Tue, 18 Jan 2022 15:04:40 +0100 Subject: [PATCH] Update MultiFieldSelect to accept a defaultValue This changes the multi select control to accept defaultValues. As these are passed in as strings (flattened arrays in the form of "1, 2, 3") they need to be split into an array to be accepted by the control. --- .../components/app/forms/MultiFieldSelect.svelte | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/app/forms/MultiFieldSelect.svelte b/packages/client/src/components/app/forms/MultiFieldSelect.svelte index cecc569b6f..06811f3e05 100644 --- a/packages/client/src/components/app/forms/MultiFieldSelect.svelte +++ b/packages/client/src/components/app/forms/MultiFieldSelect.svelte @@ -20,6 +20,7 @@ let fieldSchema $: flatOptions = optionsSource == null || optionsSource === "schema" + $: expandedValue = expand(fieldState?.value) $: options = getOptions( optionsSource, fieldSchema, @@ -28,6 +29,18 @@ valueColumn, customOptions ) + + const expand = values => { + if (!values) { + return [] + } + + if (Array.isArray(values)) { + return values + } + + return values.split(",") + } {#if fieldState} x : x => x.label} getOptionValue={flatOptions ? x => x : x => x.value}