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