From bada64126281de16aa42c3fa4dc8ca7404aeadc8 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 18 Jul 2023 16:47:43 +0100 Subject: [PATCH] Fix bug in checkboxgroup due to reassignment of value prop --- .../bbui/src/Form/Core/CheckboxGroup.svelte | 23 ++++++++++--------- .../app/forms/MultiFieldSelect.svelte | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/bbui/src/Form/Core/CheckboxGroup.svelte b/packages/bbui/src/Form/Core/CheckboxGroup.svelte index 640d5d99cd..2b8a1e438a 100644 --- a/packages/bbui/src/Form/Core/CheckboxGroup.svelte +++ b/packages/bbui/src/Form/Core/CheckboxGroup.svelte @@ -12,23 +12,24 @@ export let getOptionValue = option => option const dispatch = createEventDispatcher() + const onChange = e => { - let tempValue = value - let isChecked = e.target.checked - if (!tempValue.includes(e.target.value) && isChecked) { - tempValue.push(e.target.value) + const optionValue = e.target.value + if (e.target.checked && !value.includes(optionValue)) { + dispatch("change", [...value, optionValue]) + } else { + dispatch( + "change", + value.filter(x => x !== optionValue) + ) } - value = tempValue - dispatch( - "change", - tempValue.filter(val => val !== e.target.value || isChecked) - ) }
{#if options && Array.isArray(options)} {#each options as option} + {@const optionValue = getOptionValue(option)}
value.trim()) }