Fix multiselect
This commit is contained in:
parent
2978b5db89
commit
087e8ed153
|
@ -4,7 +4,7 @@
|
||||||
import Field from "./Field.svelte"
|
import Field from "./Field.svelte"
|
||||||
|
|
||||||
export let value = null
|
export let value = null
|
||||||
export let label = undefined
|
export let label = []
|
||||||
export let disabled = false
|
export let disabled = false
|
||||||
export let labelPosition = "above"
|
export let labelPosition = "above"
|
||||||
export let error = null
|
export let error = null
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
$: fieldText = getFieldText(value)
|
$: fieldText = getFieldText(value)
|
||||||
$: valueLookupMap = getValueLookupMap(value)
|
$: valueLookupMap = getValueLookupMap(value)
|
||||||
$: isOptionSelected = option => valueLookupMap[option] === true
|
$: isOptionSelected = option => {
|
||||||
|
return valueLookupMap[option] === true
|
||||||
|
}
|
||||||
|
|
||||||
const getFieldText = value => {
|
const getFieldText = value => {
|
||||||
if (value?.length) {
|
if (value?.length) {
|
||||||
|
@ -29,21 +31,20 @@
|
||||||
let map = {}
|
let map = {}
|
||||||
if (value?.length) {
|
if (value?.length) {
|
||||||
value.forEach(option => {
|
value.forEach(option => {
|
||||||
const optionValue = getOptionValue(option)
|
if (option) {
|
||||||
if (optionValue) {
|
map[option] = true
|
||||||
map[optionValue] = true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleOption = option => {
|
const toggleOption = optionValue => {
|
||||||
if (valueLookupMap[option]) {
|
if (valueLookupMap[optionValue]) {
|
||||||
const filtered = value.filter(option => option !== id)
|
const filtered = value.filter(option => option !== optionValue)
|
||||||
dispatch("change", filtered)
|
dispatch("change", filtered)
|
||||||
} else {
|
} else {
|
||||||
dispatch("change", [...value, option])
|
dispatch("change", [...value, optionValue])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue