From 9b13879b27c0355adb85696cf26f9b85a405a228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Mon, 15 Feb 2021 13:31:16 +0100 Subject: [PATCH] fixes crash when options was empty --- .../src/forms/RelationshipField.svelte | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/standard-components/src/forms/RelationshipField.svelte b/packages/standard-components/src/forms/RelationshipField.svelte index 0e47121f8c..ffe6fcda3b 100644 --- a/packages/standard-components/src/forms/RelationshipField.svelte +++ b/packages/standard-components/src/forms/RelationshipField.svelte @@ -20,10 +20,9 @@ const setFieldText = (value) => { if (fieldSchema?.oneToMany) { - if (value?.length) { - const row = options.find(row => row._id === value) - if (!row) return placeholder || 'Choose an option' - return getDisplayName(row) + if (value?.length && options?.length) { + const row = options.find(row => row._id === value[0]) + return row.name } else { return placeholder || 'Choose an option' } @@ -36,9 +35,7 @@ } } - $: console.log(placeholder) - - $: fieldText = setFieldText($fieldState?.value) + $: options, fieldText = setFieldText($fieldState?.value) $: valueLookupMap = getValueLookupMap($fieldState?.value) $: isOptionSelected = option => valueLookupMap[option] === true $: linkedTableId = fieldSchema?.tableId