fixes crash when options was empty

This commit is contained in:
Keviin Åberg Kultalahti 2021-02-15 13:31:16 +01:00
parent 896c6ae5d4
commit ce382f88de
1 changed files with 4 additions and 7 deletions

View File

@ -20,10 +20,9 @@
const setFieldText = (value) => { const setFieldText = (value) => {
if (fieldSchema?.oneToMany) { if (fieldSchema?.oneToMany) {
if (value?.length) { if (value?.length && options?.length) {
const row = options.find(row => row._id === value) const row = options.find(row => row._id === value[0])
if (!row) return placeholder || 'Choose an option' return row.name
return getDisplayName(row)
} else { } else {
return placeholder || 'Choose an option' return placeholder || 'Choose an option'
} }
@ -36,9 +35,7 @@
} }
} }
$: console.log(placeholder) $: options, fieldText = setFieldText($fieldState?.value)
$: fieldText = setFieldText($fieldState?.value)
$: valueLookupMap = getValueLookupMap($fieldState?.value) $: valueLookupMap = getValueLookupMap($fieldState?.value)
$: isOptionSelected = option => valueLookupMap[option] === true $: isOptionSelected = option => valueLookupMap[option] === true
$: linkedTableId = fieldSchema?.tableId $: linkedTableId = fieldSchema?.tableId