From bb4ee20bd624f3f0f806589912ecf8da0c618c02 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 17 Oct 2022 12:03:13 +0100 Subject: [PATCH] Values or defaults passed to the picker are parsed to ensure only valid options are marked/added to the component. --- .../bbui/src/Form/Core/Multiselect.svelte | 22 ++++++++++++++++--- .../common/bindings/BindingPanel.svelte | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/bbui/src/Form/Core/Multiselect.svelte b/packages/bbui/src/Form/Core/Multiselect.svelte index eb39e39042..3fbbaf5d4a 100644 --- a/packages/bbui/src/Form/Core/Multiselect.svelte +++ b/packages/bbui/src/Form/Core/Multiselect.svelte @@ -15,12 +15,28 @@ export let sort = false export let autoWidth = false + $: streamed = Array.isArray(value) + ? value.reduce((acc, ele) => { + if (typeof ele === "string") { + let temp = ele.trim() + if (!temp) { + return acc + } + } + let processedOpt = ele.toString() + if (options.indexOf(processedOpt) > -1) { + acc.push(ele.toString()) + } + return acc + }, []) + : [] + const dispatch = createEventDispatcher() - $: selectedLookupMap = getSelectedLookupMap(value) + $: selectedLookupMap = getSelectedLookupMap(streamed) $: optionLookupMap = getOptionLookupMap(options) - $: fieldText = getFieldText(value, optionLookupMap, placeholder) + $: fieldText = getFieldText(streamed, optionLookupMap, placeholder) $: isOptionSelected = optionValue => selectedLookupMap[optionValue] === true - $: toggleOption = makeToggleOption(selectedLookupMap, value) + $: toggleOption = makeToggleOption(selectedLookupMap, streamed) const getFieldText = (value, map, placeholder) => { if (Array.isArray(value) && value.length > 0) { diff --git a/packages/builder/src/components/common/bindings/BindingPanel.svelte b/packages/builder/src/components/common/bindings/BindingPanel.svelte index 1a1714967d..d105253e14 100644 --- a/packages/builder/src/components/common/bindings/BindingPanel.svelte +++ b/packages/builder/src/components/common/bindings/BindingPanel.svelte @@ -247,7 +247,7 @@ return } hoverTarget = { - title: binding.display?.name || binding.fieldSchema.name, + title: binding.display?.name || binding.fieldSchema?.name, description: binding.description, } popover.show()