Allow multiselect component and field to support text values
This commit is contained in:
parent
08463c1cd0
commit
c627cb60c3
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue