Update MultiFieldSelect to accept a defaultValue
This changes the multi select control to accept defaultValues. As these are passed in as strings (flattened arrays in the form of "1, 2, 3") they need to be split into an array to be accepted by the control.
This commit is contained in:
parent
8798f5cf37
commit
d2ffc2e920
|
@ -20,6 +20,7 @@
|
||||||
let fieldSchema
|
let fieldSchema
|
||||||
|
|
||||||
$: flatOptions = optionsSource == null || optionsSource === "schema"
|
$: flatOptions = optionsSource == null || optionsSource === "schema"
|
||||||
|
$: expandedValue = expand(fieldState?.value)
|
||||||
$: options = getOptions(
|
$: options = getOptions(
|
||||||
optionsSource,
|
optionsSource,
|
||||||
fieldSchema,
|
fieldSchema,
|
||||||
|
@ -28,6 +29,18 @@
|
||||||
valueColumn,
|
valueColumn,
|
||||||
customOptions
|
customOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const expand = values => {
|
||||||
|
if (!values) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(values)) {
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
|
return values.split(",")
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Field
|
<Field
|
||||||
|
@ -43,7 +56,7 @@
|
||||||
>
|
>
|
||||||
{#if fieldState}
|
{#if fieldState}
|
||||||
<CoreMultiselect
|
<CoreMultiselect
|
||||||
value={fieldState.value || []}
|
value={expandedValue}
|
||||||
error={fieldState.error}
|
error={fieldState.error}
|
||||||
getOptionLabel={flatOptions ? x => x : x => x.label}
|
getOptionLabel={flatOptions ? x => x : x => x.label}
|
||||||
getOptionValue={flatOptions ? x => x : x => x.value}
|
getOptionValue={flatOptions ? x => x : x => x.value}
|
||||||
|
|
Loading…
Reference in New Issue