Fixes for Single select and Single user pickers. Now displaying binding status correctly

This commit is contained in:
Dean 2024-08-06 11:58:12 +01:00
parent 8279a0b31c
commit 853e891664
4 changed files with 22 additions and 10 deletions

View File

@ -157,7 +157,7 @@
</span>
{:else if schema.type === "link"}
<LinkedRowSelector
linkedRows={fieldData}
linkedData={fieldData}
{schema}
on:change={e =>
onChange({
@ -169,7 +169,7 @@
/>
{:else if schema.type === "bb_reference" || schema.type === "bb_reference_single"}
<LinkedRowSelector
linkedRows={fieldData}
linkedData={fieldData}
{schema}
linkedTableId={"ta_users"}
on:change={e =>

View File

@ -146,7 +146,7 @@
{:else if type === "link"}
<LinkedRowSelector
{error}
linkedRows={value}
linkedData={value}
schema={meta}
on:change={e => (value = e.detail)}
/>

View File

@ -6,7 +6,7 @@
import { createEventDispatcher } from "svelte"
export let schema
export let linkedRows = []
export let linkedData
export let useLabel = true
export let linkedTableId
export let label
@ -15,14 +15,25 @@
let rows = []
let linkedIds = []
$: linkedIds = (Array.isArray(linkedRows) ? linkedRows : [])?.map(
row => row?._id || row
)
$: fieldValue = getFieldValue(linkedData)
$: label = label || capitalise(schema.name)
$: linkedTableId = linkedTableId || schema.tableId
$: linkedTable = $tables.list.find(table => table._id === linkedTableId)
$: fetchRows(linkedTableId)
const getFieldValue = val => {
const linkedIds = (Array.isArray(val) ? val : [])?.map(
row => row?._id || row
)
if (schema.relationshipType === "one-to-many") {
return linkedIds?.[0]
} else if (schema.type === "bb_reference_single") {
return val
} else {
return linkedIds
}
}
async function fetchRows(linkedTableId) {
try {
rows = await API.fetchTableData(linkedTableId)
@ -45,7 +56,7 @@
</Label>
{:else if schema.relationshipType === "one-to-many" || schema.type === "bb_reference_single"}
<Select
value={linkedIds?.[0]}
value={fieldValue}
options={rows}
getOptionLabel={getPrettyName}
getOptionValue={row => row._id}
@ -58,7 +69,7 @@
/>
{:else}
<Multiselect
value={linkedIds}
value={fieldValue}
label={useLabel ? label : null}
options={rows}
getOptionLabel={getPrettyName}

View File

@ -8,7 +8,7 @@
import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte"
import { createEventDispatcher, setContext } from "svelte"
import { isJSBinding } from "@budibase/string-templates"
import { isJSBinding, findHBSBlocks } from "@budibase/string-templates"
export let panel = ClientBindingPanel
export let value = ""
@ -109,6 +109,7 @@
array: hasValidOptions,
longform: value => !isJSBinding(value),
json: value => !isJSBinding(value),
options: value => !isJSBinding(value) && !findHBSBlocks(value)?.length,
boolean: isValidBoolean,
attachment: false,
attachment_single: false,