Add default value for relationship fields
This commit is contained in:
parent
03b3049572
commit
a2a3b276d0
|
@ -2537,6 +2537,11 @@
|
|||
"label": "Placeholder",
|
||||
"key": "placeholder"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"label": "Default value",
|
||||
"key": "defaultValue"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"label": "Autocomplete",
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
export let disabled = false
|
||||
export let validation
|
||||
export let autocomplete = false
|
||||
export let defaultValue
|
||||
|
||||
let fieldState
|
||||
let fieldApi
|
||||
|
@ -27,6 +28,7 @@
|
|||
$: singleValue = flatten(fieldState?.value)?.[0]
|
||||
$: multiValue = flatten(fieldState?.value) ?? []
|
||||
$: component = multiselect ? CoreMultiselect : CoreSelect
|
||||
$: expandedDefaultValue = expand(defaultValue)
|
||||
|
||||
const fetchTable = async id => {
|
||||
if (id) {
|
||||
|
@ -62,6 +64,16 @@
|
|||
const multiHandler = e => {
|
||||
fieldApi.setValue(e.detail)
|
||||
}
|
||||
|
||||
const expand = values => {
|
||||
if (!values) {
|
||||
return []
|
||||
}
|
||||
if (Array.isArray(values)) {
|
||||
return values
|
||||
}
|
||||
return values.split(",").map(value => value.trim())
|
||||
}
|
||||
</script>
|
||||
|
||||
<Field
|
||||
|
@ -69,11 +81,11 @@
|
|||
{field}
|
||||
{disabled}
|
||||
{validation}
|
||||
defaultValue={expandedDefaultValue}
|
||||
type={FieldTypes.LINK}
|
||||
bind:fieldState
|
||||
bind:fieldApi
|
||||
bind:fieldSchema
|
||||
defaultValue={[]}
|
||||
>
|
||||
{#if fieldState}
|
||||
<svelte:component
|
||||
|
|
Loading…
Reference in New Issue