From bb4ee20bd624f3f0f806589912ecf8da0c618c02 Mon Sep 17 00:00:00 2001 From: Dean Date: Mon, 17 Oct 2022 12:03:13 +0100 Subject: [PATCH 1/5] 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() From 36307ccff74b716f42bf690c53698a6c2d898b8a Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 18 Oct 2022 11:06:18 +0100 Subject: [PATCH 2/5] Refactor for multiselect value parsing and a fix to ensure default values are parsed before reaching the picker --- packages/bbui/src/Form/Core/Multiselect.svelte | 15 ++++++--------- .../client/src/components/app/forms/Field.svelte | 10 +++++++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/bbui/src/Form/Core/Multiselect.svelte b/packages/bbui/src/Form/Core/Multiselect.svelte index 3fbbaf5d4a..c76f5324c5 100644 --- a/packages/bbui/src/Form/Core/Multiselect.svelte +++ b/packages/bbui/src/Form/Core/Multiselect.svelte @@ -16,16 +16,13 @@ export let autoWidth = false $: streamed = Array.isArray(value) - ? value.reduce((acc, ele) => { - if (typeof ele === "string") { - let temp = ele.trim() - if (!temp) { - return acc - } + ? value.reduce((acc, entry) => { + if (typeof ele === "string" && entry.trim() === "") { + return acc } - let processedOpt = ele.toString() - if (options.indexOf(processedOpt) > -1) { - acc.push(ele.toString()) + let processedOption = String(entry) + if (options.indexOf(processedOption) > -1) { + acc.push(processedOption) } return acc }, []) diff --git a/packages/client/src/components/app/forms/Field.svelte b/packages/client/src/components/app/forms/Field.svelte index 9a91ea5b2d..1203630de5 100644 --- a/packages/client/src/components/app/forms/Field.svelte +++ b/packages/client/src/components/app/forms/Field.svelte @@ -27,11 +27,19 @@ $: formField = formApi?.registerField( field, type, - defaultValue, + parseDefaultValue(defaultValue), disabled, validation, formStep ) + + const parseDefaultValue = defaultValue => { + if (Array.isArray(defaultValue) && type === "array") { + return defaultValue.map(val => String(val)) + } + return defaultValue + } + $: schemaType = fieldSchema?.type !== "formula" ? fieldSchema?.type : "string" // Focus label when editing From 7ccf29bff705b724ed1505133cbb9816946a5c9d Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 18 Oct 2022 16:24:36 +0100 Subject: [PATCH 3/5] Pushed default parsing up into the InnerForm component to ensure that invalid default values are removed entirely. Fixes for custom validation for array types --- .../bbui/src/Form/Core/Multiselect.svelte | 19 +++----------- packages/bbui/src/Form/Core/Select.svelte | 2 +- .../ValidationEditor/ValidationDrawer.svelte | 3 +++ .../src/components/app/forms/Field.svelte | 9 +------ .../src/components/app/forms/InnerForm.svelte | 26 ++++++++++++++++--- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/packages/bbui/src/Form/Core/Multiselect.svelte b/packages/bbui/src/Form/Core/Multiselect.svelte index c76f5324c5..eb39e39042 100644 --- a/packages/bbui/src/Form/Core/Multiselect.svelte +++ b/packages/bbui/src/Form/Core/Multiselect.svelte @@ -15,25 +15,12 @@ export let sort = false export let autoWidth = false - $: streamed = Array.isArray(value) - ? value.reduce((acc, entry) => { - if (typeof ele === "string" && entry.trim() === "") { - return acc - } - let processedOption = String(entry) - if (options.indexOf(processedOption) > -1) { - acc.push(processedOption) - } - return acc - }, []) - : [] - const dispatch = createEventDispatcher() - $: selectedLookupMap = getSelectedLookupMap(streamed) + $: selectedLookupMap = getSelectedLookupMap(value) $: optionLookupMap = getOptionLookupMap(options) - $: fieldText = getFieldText(streamed, optionLookupMap, placeholder) + $: fieldText = getFieldText(value, optionLookupMap, placeholder) $: isOptionSelected = optionValue => selectedLookupMap[optionValue] === true - $: toggleOption = makeToggleOption(selectedLookupMap, streamed) + $: toggleOption = makeToggleOption(selectedLookupMap, value) const getFieldText = (value, map, placeholder) => { if (Array.isArray(value) && value.length > 0) { diff --git a/packages/bbui/src/Form/Core/Select.svelte b/packages/bbui/src/Form/Core/Select.svelte index f549f58d0c..fbb7f80c13 100644 --- a/packages/bbui/src/Form/Core/Select.svelte +++ b/packages/bbui/src/Form/Core/Select.svelte @@ -36,7 +36,7 @@ const getFieldText = (value, options, placeholder) => { // Always use placeholder if no value - if (value == null || value === "") { + if (value == null || value === "" || value.length == 0) { return placeholder || "Choose an option" } diff --git a/packages/builder/src/components/design/settings/controls/ValidationEditor/ValidationDrawer.svelte b/packages/builder/src/components/design/settings/controls/ValidationEditor/ValidationDrawer.svelte index 081e748caf..2624c28e7f 100644 --- a/packages/builder/src/components/design/settings/controls/ValidationEditor/ValidationDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/ValidationEditor/ValidationDrawer.svelte @@ -305,6 +305,9 @@ getOptionLabel={x => x} getOptionValue={x => x} value={rule.value} + on:change={e => { + rule.value = e.detail + }} /> {:else if rule.type === "boolean"}