1
0
Fork 0
mirror of synced 2024-10-02 18:16:29 +13:00

initial standard-components relationship field component update

This commit is contained in:
Keviin Åberg Kultalahti 2021-02-12 16:47:20 +01:00
parent 9c3bde0f7e
commit b3964dddbb
3 changed files with 37 additions and 2 deletions

View file

@ -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: "" })
} }

View file

@ -1333,6 +1333,11 @@
"type": "text", "type": "text",
"label": "Label", "label": "Label",
"key": "label" "key": "label"
},
{
"type": "text",
"label": "Placeholder",
"key": "placeholder"
} }
] ]
} }

View file

@ -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 = ""
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'
}
}
}
$: fieldText = `${$fieldState?.value?.length ?? 0} selected rows` $: 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,11 +76,15 @@
} }
const toggleOption = option => { const toggleOption = option => {
if ($fieldState.value.includes(option)) { if (fieldSchema.oneToMany) {
fieldApi.setValue([option])
} else {
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>