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()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
$: selectedLookupMap = getSelectedLookupMap(value)
|
$: arrayValue = Array.isArray(value) ? value : [value].filter(x => !!x)
|
||||||
|
$: selectedLookupMap = getSelectedLookupMap(arrayValue)
|
||||||
$: optionLookupMap = getOptionLookupMap(options)
|
$: optionLookupMap = getOptionLookupMap(options)
|
||||||
|
|
||||||
$: fieldText = getFieldText(value, optionLookupMap, placeholder)
|
$: fieldText = getFieldText(arrayValue, optionLookupMap, placeholder)
|
||||||
$: isOptionSelected = optionValue => selectedLookupMap[optionValue] === true
|
$: isOptionSelected = optionValue => selectedLookupMap[optionValue] === true
|
||||||
$: toggleOption = makeToggleOption(selectedLookupMap, value)
|
$: toggleOption = makeToggleOption(selectedLookupMap, arrayValue)
|
||||||
|
|
||||||
const getFieldText = (value, map, placeholder) => {
|
const getFieldText = (value, map, placeholder) => {
|
||||||
if (Array.isArray(value) && value.length > 0) {
|
if (Array.isArray(value) && value.length > 0) {
|
||||||
|
@ -81,7 +82,7 @@
|
||||||
{readonly}
|
{readonly}
|
||||||
{fieldText}
|
{fieldText}
|
||||||
{options}
|
{options}
|
||||||
isPlaceholder={!value?.length}
|
isPlaceholder={!arrayValue.length}
|
||||||
{autocomplete}
|
{autocomplete}
|
||||||
{isOptionSelected}
|
{isOptionSelected}
|
||||||
{getOptionLabel}
|
{getOptionLabel}
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
|
|
||||||
const displayLimit = 5
|
const displayLimit = 5
|
||||||
|
|
||||||
$: badges = Array.isArray(value) ? value.slice(0, displayLimit) : []
|
$: arrayValue = Array.isArray(value) ? value : [value].filter(x => !!x)
|
||||||
$: leftover = (value?.length ?? 0) - badges.length
|
$: badges = arrayValue.slice(0, displayLimit)
|
||||||
|
$: leftover = arrayValue.length - badges.length
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each badges as badge}
|
{#each badges as badge}
|
||||||
|
|
Loading…
Reference in New Issue