From 0899b988a485519b92d58fb2bad31d7ff363acee Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 4 Feb 2022 08:50:56 +0000 Subject: [PATCH] Add default value for relationship fields --- packages/client/manifest.json | 5 +++++ .../components/app/forms/RelationshipField.svelte | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 04ffdffa21..1b83577564 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -2537,6 +2537,11 @@ "label": "Placeholder", "key": "placeholder" }, + { + "type": "text", + "label": "Default value", + "key": "defaultValue" + }, { "type": "boolean", "label": "Autocomplete", diff --git a/packages/client/src/components/app/forms/RelationshipField.svelte b/packages/client/src/components/app/forms/RelationshipField.svelte index dbf708f893..e36e438db7 100644 --- a/packages/client/src/components/app/forms/RelationshipField.svelte +++ b/packages/client/src/components/app/forms/RelationshipField.svelte @@ -12,6 +12,7 @@ export let disabled = false export let validation export let autocomplete = false + export let defaultValue let fieldState let fieldApi @@ -27,6 +28,7 @@ $: singleValue = flatten(fieldState?.value)?.[0] $: multiValue = flatten(fieldState?.value) ?? [] $: component = multiselect ? CoreMultiselect : CoreSelect + $: expandedDefaultValue = expand(defaultValue) const fetchTable = async id => { if (id) { @@ -62,6 +64,16 @@ const multiHandler = e => { fieldApi.setValue(e.detail) } + + const expand = values => { + if (!values) { + return [] + } + if (Array.isArray(values)) { + return values + } + return values.split(",").map(value => value.trim()) + } {#if fieldState}