From 5f0a7c5aac705dc22f631ff8d6385bacbd285262 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 25 Apr 2024 13:58:56 +0200 Subject: [PATCH] Cleans --- .../app/forms/RelationshipField.svelte | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/client/src/components/app/forms/RelationshipField.svelte b/packages/client/src/components/app/forms/RelationshipField.svelte index e59a77c8c2..a85b636851 100644 --- a/packages/client/src/components/app/forms/RelationshipField.svelte +++ b/packages/client/src/components/app/forms/RelationshipField.svelte @@ -51,7 +51,6 @@ ? flatten(fieldState?.value) ?? [] : flatten(fieldState?.value)?.[0] $: component = multiselect ? CoreMultiselect : CoreSelect - $: expandedDefaultValue = expand(defaultValue) $: primaryDisplay = primaryDisplay || tableDefinition?.primaryDisplay let optionsObj @@ -115,7 +114,6 @@ const forceFetchRows = async () => { fieldApi?.setValue([]) - selectedValue = [] debouncedFetchRows(searchTerm, primaryDisplay, defaultValue) } const fetchRows = async (searchTerm, primaryDisplay, defaultVal) => { @@ -157,6 +155,7 @@ if (!values) { return [] } + if (!Array.isArray(values)) { values = [values] } @@ -170,22 +169,20 @@ return row?.[primaryDisplay] || "-" } - const expand = values => { - if (!values) { - return [] - } - if (Array.isArray(values)) { - return values - } - return values.split(",").map(value => value.trim()) - } - const handleChange = e => { let value = e.detail - if (!multiselect && type !== FieldType.BB_REFERENCE_SINGLE) { + if (!multiselect) { value = value == null ? [] : [value] } + if ( + type === FieldType.BB_REFERENCE_SINGLE && + value && + Array.isArray(value) + ) { + value = value[0] + } + const changed = fieldApi.setValue(value) if (onChange && changed) { onChange({ @@ -207,7 +204,7 @@ {disabled} {readonly} {validation} - defaultValue={expandedDefaultValue} + {defaultValue} {type} {span} {helpText}