From 087e8ed153f1b40c6eaf94586d75ee52e23e9cfa Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 15 Apr 2021 12:14:51 +0100 Subject: [PATCH] Fix multiselect --- packages/bbui/src/Form/Multiselect.svelte | 2 +- .../bbui/src/Form/internal/Multiselect.svelte | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/bbui/src/Form/Multiselect.svelte b/packages/bbui/src/Form/Multiselect.svelte index f6c4c1f188..19a99ba816 100644 --- a/packages/bbui/src/Form/Multiselect.svelte +++ b/packages/bbui/src/Form/Multiselect.svelte @@ -4,7 +4,7 @@ import Field from "./Field.svelte" export let value = null - export let label = undefined + export let label = [] export let disabled = false export let labelPosition = "above" export let error = null diff --git a/packages/bbui/src/Form/internal/Multiselect.svelte b/packages/bbui/src/Form/internal/Multiselect.svelte index e1df4ae575..23475a1417 100644 --- a/packages/bbui/src/Form/internal/Multiselect.svelte +++ b/packages/bbui/src/Form/internal/Multiselect.svelte @@ -14,7 +14,9 @@ const dispatch = createEventDispatcher() $: fieldText = getFieldText(value) $: valueLookupMap = getValueLookupMap(value) - $: isOptionSelected = option => valueLookupMap[option] === true + $: isOptionSelected = option => { + return valueLookupMap[option] === true + } const getFieldText = value => { if (value?.length) { @@ -29,21 +31,20 @@ let map = {} if (value?.length) { value.forEach(option => { - const optionValue = getOptionValue(option) - if (optionValue) { - map[optionValue] = true + if (option) { + map[option] = true } }) } return map } - const toggleOption = option => { - if (valueLookupMap[option]) { - const filtered = value.filter(option => option !== id) + const toggleOption = optionValue => { + if (valueLookupMap[optionValue]) { + const filtered = value.filter(option => option !== optionValue) dispatch("change", filtered) } else { - dispatch("change", [...value, option]) + dispatch("change", [...value, optionValue]) } }