initial standard-components relationship field component update
This commit is contained in:
parent
5afeb600a6
commit
8539a6dcbe
|
@ -194,6 +194,10 @@ export function makeDatasourceFormComponents(datasource) {
|
||||||
if (fieldType === "options") {
|
if (fieldType === "options") {
|
||||||
component.customProps({ placeholder: "Choose an option " })
|
component.customProps({ placeholder: "Choose an option " })
|
||||||
}
|
}
|
||||||
|
if (fieldType === "link") {
|
||||||
|
let placeholder = fieldSchema.oneToMany ? 'Choose an option' : 'Choose some options'
|
||||||
|
component.customProps({ placeholder })
|
||||||
|
}
|
||||||
if (fieldType === "boolean") {
|
if (fieldType === "boolean") {
|
||||||
component.customProps({ text: field, label: "" })
|
component.customProps({ text: field, label: "" })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1333,6 +1333,11 @@
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"label": "Label",
|
"label": "Label",
|
||||||
"key": "label"
|
"key": "label"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"label": "Placeholder",
|
||||||
|
"key": "placeholder"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
export let field
|
export let field
|
||||||
export let label
|
export let label
|
||||||
|
export let placeholder
|
||||||
|
|
||||||
let fieldState
|
let fieldState
|
||||||
let fieldApi
|
let fieldApi
|
||||||
|
@ -15,8 +16,29 @@
|
||||||
// Picker state
|
// Picker state
|
||||||
let options = []
|
let options = []
|
||||||
let tableDefinition
|
let tableDefinition
|
||||||
|
let fieldText = ""
|
||||||
|
|
||||||
$: fieldText = `${$fieldState?.value?.length ?? 0} selected rows`
|
const setFieldText = (value) => {
|
||||||
|
if (fieldSchema?.oneToMany) {
|
||||||
|
if (value?.length) {
|
||||||
|
const row = options.find(row => row._id === value)
|
||||||
|
if (!row) return placeholder || 'Choose an option'
|
||||||
|
return getDisplayName(row)
|
||||||
|
} else {
|
||||||
|
return placeholder || 'Choose an option'
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (value?.length) {
|
||||||
|
return `${value?.length ?? 0} selected rows`
|
||||||
|
} else {
|
||||||
|
return placeholder || 'Choose some options'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: console.log(placeholder)
|
||||||
|
|
||||||
|
$: fieldText = setFieldText($fieldState?.value)
|
||||||
$: valueLookupMap = getValueLookupMap($fieldState?.value)
|
$: valueLookupMap = getValueLookupMap($fieldState?.value)
|
||||||
$: isOptionSelected = option => valueLookupMap[option] === true
|
$: isOptionSelected = option => valueLookupMap[option] === true
|
||||||
$: linkedTableId = fieldSchema?.tableId
|
$: linkedTableId = fieldSchema?.tableId
|
||||||
|
@ -54,12 +76,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleOption = option => {
|
const toggleOption = option => {
|
||||||
|
if (fieldSchema.oneToMany) {
|
||||||
|
fieldApi.setValue([option])
|
||||||
|
} else {
|
||||||
if ($fieldState.value.includes(option)) {
|
if ($fieldState.value.includes(option)) {
|
||||||
fieldApi.setValue($fieldState.value.filter(x => x !== option))
|
fieldApi.setValue($fieldState.value.filter(x => x !== option))
|
||||||
} else {
|
} else {
|
||||||
fieldApi.setValue([...$fieldState.value, option])
|
fieldApi.setValue([...$fieldState.value, option])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Field
|
<Field
|
||||||
|
|
Loading…
Reference in New Issue