Merge pull request #8282 from Budibase/fix/multipicker-default-behaviour
Parse multi-select values/defaults to avoid unusable options.
This commit is contained in:
commit
f1c9fd175c
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import Picker from "./Picker.svelte"
|
import Picker from "./Picker.svelte"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher, onMount } from "svelte"
|
||||||
|
|
||||||
export let value = []
|
export let value = []
|
||||||
export let id = null
|
export let id = null
|
||||||
|
@ -16,8 +16,33 @@
|
||||||
export let autoWidth = false
|
export let autoWidth = false
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
const parseValues = value => {
|
||||||
|
return Array.isArray(value)
|
||||||
|
? value.reduce((acc, entry) => {
|
||||||
|
if (typeof ele === "string" && entry.trim() === "") {
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
let processedOption = String(entry)
|
||||||
|
if (options.indexOf(processedOption) > -1) {
|
||||||
|
acc.push(processedOption)
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, [])
|
||||||
|
: []
|
||||||
|
}
|
||||||
|
let loaded = false
|
||||||
|
|
||||||
|
$: combinedValues = value ? [...value].concat(options) : []
|
||||||
|
$: superSet = new Set(combinedValues)
|
||||||
|
|
||||||
|
$: if (loaded && options.length != superSet.size) {
|
||||||
|
// ensure that the values being pushed in are valid.
|
||||||
|
dispatch("change", parseValues(value))
|
||||||
|
}
|
||||||
|
|
||||||
$: selectedLookupMap = getSelectedLookupMap(value)
|
$: selectedLookupMap = getSelectedLookupMap(value)
|
||||||
$: optionLookupMap = getOptionLookupMap(options)
|
$: optionLookupMap = getOptionLookupMap(options)
|
||||||
|
|
||||||
$: fieldText = getFieldText(value, optionLookupMap, placeholder)
|
$: fieldText = getFieldText(value, optionLookupMap, placeholder)
|
||||||
$: isOptionSelected = optionValue => selectedLookupMap[optionValue] === true
|
$: isOptionSelected = optionValue => selectedLookupMap[optionValue] === true
|
||||||
$: toggleOption = makeToggleOption(selectedLookupMap, value)
|
$: toggleOption = makeToggleOption(selectedLookupMap, value)
|
||||||
|
@ -70,6 +95,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
loaded = true
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Picker
|
<Picker
|
||||||
|
|
|
@ -247,7 +247,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hoverTarget = {
|
hoverTarget = {
|
||||||
title: binding.display?.name || binding.fieldSchema.name,
|
title: binding.display?.name || binding.fieldSchema?.name,
|
||||||
description: binding.description,
|
description: binding.description,
|
||||||
}
|
}
|
||||||
popover.show()
|
popover.show()
|
||||||
|
|
|
@ -305,6 +305,9 @@
|
||||||
getOptionLabel={x => x}
|
getOptionLabel={x => x}
|
||||||
getOptionValue={x => x}
|
getOptionValue={x => x}
|
||||||
value={rule.value}
|
value={rule.value}
|
||||||
|
on:change={e => {
|
||||||
|
rule.value = e.detail
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{:else if rule.type === "boolean"}
|
{:else if rule.type === "boolean"}
|
||||||
<Select
|
<Select
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
validation,
|
validation,
|
||||||
formStep
|
formStep
|
||||||
)
|
)
|
||||||
|
|
||||||
$: schemaType = fieldSchema?.type !== "formula" ? fieldSchema?.type : "string"
|
$: schemaType = fieldSchema?.type !== "formula" ? fieldSchema?.type : "string"
|
||||||
|
|
||||||
// Focus label when editing
|
// Focus label when editing
|
||||||
|
|
|
@ -143,6 +143,7 @@
|
||||||
|
|
||||||
// Create validation function based on field schema
|
// Create validation function based on field schema
|
||||||
const schemaConstraints = schema?.[field]?.constraints
|
const schemaConstraints = schema?.[field]?.constraints
|
||||||
|
|
||||||
const validator = disableValidation
|
const validator = disableValidation
|
||||||
? null
|
? null
|
||||||
: createValidatorFromConstraints(
|
: createValidatorFromConstraints(
|
||||||
|
|
Loading…
Reference in New Issue