From 0e4a7ace08f6748b67ba2269a373be0a9b9bb9fe Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 18 Oct 2022 16:24:36 +0100 Subject: [PATCH] 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"}