Allow multiselect component and field to support text values

This commit is contained in:
Andrew Kingston 2023-02-20 18:45:35 +00:00
parent 08463c1cd0
commit c627cb60c3
3 changed files with 8 additions and 6 deletions

View File

@ -17,12 +17,13 @@
const dispatch = createEventDispatcher()
$: selectedLookupMap = getSelectedLookupMap(value)
$: arrayValue = Array.isArray(value) ? value : [value].filter(x => !!x)
$: selectedLookupMap = getSelectedLookupMap(arrayValue)
$: optionLookupMap = getOptionLookupMap(options)
$: fieldText = getFieldText(value, optionLookupMap, placeholder)
$: fieldText = getFieldText(arrayValue, optionLookupMap, placeholder)
$: isOptionSelected = optionValue => selectedLookupMap[optionValue] === true
$: toggleOption = makeToggleOption(selectedLookupMap, value)
$: toggleOption = makeToggleOption(selectedLookupMap, arrayValue)
const getFieldText = (value, map, placeholder) => {
if (Array.isArray(value) && value.length > 0) {
@ -81,7 +82,7 @@
{readonly}
{fieldText}
{options}
isPlaceholder={!value?.length}
isPlaceholder={!arrayValue.length}
{autocomplete}
{isOptionSelected}
{getOptionLabel}

View File

@ -5,8 +5,9 @@
const displayLimit = 5
$: badges = Array.isArray(value) ? value.slice(0, displayLimit) : []
$: leftover = (value?.length ?? 0) - badges.length
$: arrayValue = Array.isArray(value) ? value : [value].filter(x => !!x)
$: badges = arrayValue.slice(0, displayLimit)
$: leftover = arrayValue.length - badges.length
</script>
{#each badges as badge}