From dd44c4e7e3559a35a51c8aa668e44664ea0cd053 Mon Sep 17 00:00:00 2001 From: Bastiaan Terhorst Date: Tue, 18 Jan 2022 15:04:40 +0100 Subject: [PATCH 1/3] 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} From 54a1c84179142d10bb16abf387161ff58b7e04a9 Mon Sep 17 00:00:00 2001 From: Bastiaan Terhorst Date: Tue, 18 Jan 2022 16:48:08 +0100 Subject: [PATCH 2/3] also set defaultValue --- .../client/src/components/app/forms/MultiFieldSelect.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/app/forms/MultiFieldSelect.svelte b/packages/client/src/components/app/forms/MultiFieldSelect.svelte index 06811f3e05..5705b28e14 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" + $: expandedDefaultValue = expand(fieldState?.defaultValue) $: expandedValue = expand(fieldState?.value) $: options = getOptions( optionsSource, @@ -39,7 +40,7 @@ return values } - return values.split(",") + return values.split(",").map(value => value.trim()) } @@ -57,6 +58,7 @@ {#if fieldState} x : x => x.label} getOptionValue={flatOptions ? x => x : x => x.value} From 107aa44308eb671032ab786445e957ec271f184a Mon Sep 17 00:00:00 2001 From: Bastiaan Terhorst Date: Wed, 19 Jan 2022 09:19:49 +0100 Subject: [PATCH 3/3] set defaultValue in Field component --- .../src/components/app/forms/MultiFieldSelect.svelte | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/client/src/components/app/forms/MultiFieldSelect.svelte b/packages/client/src/components/app/forms/MultiFieldSelect.svelte index 5705b28e14..686198dfe1 100644 --- a/packages/client/src/components/app/forms/MultiFieldSelect.svelte +++ b/packages/client/src/components/app/forms/MultiFieldSelect.svelte @@ -20,8 +20,7 @@ let fieldSchema $: flatOptions = optionsSource == null || optionsSource === "schema" - $: expandedDefaultValue = expand(fieldState?.defaultValue) - $: expandedValue = expand(fieldState?.value) + $: expandedDefaultValue = expand(defaultValue) $: options = getOptions( optionsSource, fieldSchema, @@ -49,7 +48,7 @@ {label} {disabled} {validation} - {defaultValue} + defaultValue={expandedDefaultValue} type="array" bind:fieldState bind:fieldApi @@ -57,8 +56,7 @@ > {#if fieldState} x : x => x.label} getOptionValue={flatOptions ? x => x : x => x.value}