1
0
Fork 0
mirror of synced 2024-06-02 02:25:17 +12: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 5afeb600a6
commit 8539a6dcbe
3 changed files with 37 additions and 2 deletions

View file

@ -194,6 +194,10 @@ export function makeDatasourceFormComponents(datasource) {
if (fieldType === "options") {
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") {
component.customProps({ text: field, label: "" })
}

View file

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

View file

@ -7,6 +7,7 @@
export let field
export let label
export let placeholder
let fieldState
let fieldApi
@ -15,8 +16,29 @@
// Picker state
let options = []
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)
$: isOptionSelected = option => valueLookupMap[option] === true
$: linkedTableId = fieldSchema?.tableId
@ -54,11 +76,15 @@
}
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))
} else {
fieldApi.setValue([...$fieldState.value, option])
}
}
}
</script>