Refactor for multiselect value parsing and a fix to ensure default values are parsed before reaching the picker

This commit is contained in:
Dean 2022-10-18 11:06:18 +01:00
parent a0a9d35b50
commit b31f7f4b87
2 changed files with 15 additions and 10 deletions

View File

@ -16,16 +16,13 @@
export let autoWidth = false
$: streamed = Array.isArray(value)
? value.reduce((acc, ele) => {
if (typeof ele === "string") {
let temp = ele.trim()
if (!temp) {
return acc
}
? value.reduce((acc, entry) => {
if (typeof ele === "string" && entry.trim() === "") {
return acc
}
let processedOpt = ele.toString()
if (options.indexOf(processedOpt) > -1) {
acc.push(ele.toString())
let processedOption = String(entry)
if (options.indexOf(processedOption) > -1) {
acc.push(processedOption)
}
return acc
}, [])

View File

@ -27,11 +27,19 @@
$: formField = formApi?.registerField(
field,
type,
defaultValue,
parseDefaultValue(defaultValue),
disabled,
validation,
formStep
)
const parseDefaultValue = defaultValue => {
if (Array.isArray(defaultValue) && type === "array") {
return defaultValue.map(val => String(val))
}
return defaultValue
}
$: schemaType = fieldSchema?.type !== "formula" ? fieldSchema?.type : "string"
// Focus label when editing