Use fetch updates for the autocomplete
This commit is contained in:
parent
44bf32981a
commit
1191e71a15
|
@ -21,6 +21,7 @@
|
||||||
let fieldApi
|
let fieldApi
|
||||||
let fieldSchema
|
let fieldSchema
|
||||||
let tableDefinition
|
let tableDefinition
|
||||||
|
let fetchTerm
|
||||||
|
|
||||||
$: multiselect = fieldSchema?.relationshipType !== "one-to-many"
|
$: multiselect = fieldSchema?.relationshipType !== "one-to-many"
|
||||||
$: linkedTableId = fieldSchema?.tableId
|
$: linkedTableId = fieldSchema?.tableId
|
||||||
|
@ -35,13 +36,25 @@
|
||||||
limit: 100,
|
limit: 100,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
$: fetch.update({ filter })
|
|
||||||
$: options = $fetch.rows
|
$: options = $fetch.rows
|
||||||
$: tableDefinition = $fetch.definition
|
$: tableDefinition = $fetch.definition
|
||||||
$: 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)
|
$: expandedDefaultValue = expand(defaultValue)
|
||||||
|
$: primaryDisplay = tableDefinition?.primaryDisplay || "_id"
|
||||||
|
|
||||||
|
let prevTerm
|
||||||
|
$: {
|
||||||
|
// Check if the fetch changed, ignoring differences between empty/null/undefined
|
||||||
|
if (primaryDisplay && prevTerm != fetchTerm) {
|
||||||
|
prevTerm = fetchTerm
|
||||||
|
fetch.update({
|
||||||
|
query: { string: { [primaryDisplay]: fetchTerm } },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const flatten = values => {
|
const flatten = values => {
|
||||||
if (!values) {
|
if (!values) {
|
||||||
|
@ -54,7 +67,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDisplayName = row => {
|
const getDisplayName = row => {
|
||||||
return row?.[tableDefinition?.primaryDisplay || "_id"] || "-"
|
return row?.[primaryDisplay] || "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
const singleHandler = e => {
|
const singleHandler = e => {
|
||||||
|
@ -107,7 +120,9 @@
|
||||||
getOptionLabel={getDisplayName}
|
getOptionLabel={getDisplayName}
|
||||||
getOptionValue={option => option._id}
|
getOptionValue={option => option._id}
|
||||||
{placeholder}
|
{placeholder}
|
||||||
sort={true}
|
sort
|
||||||
|
useFetch
|
||||||
|
bind:fetchTerm
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</Field>
|
</Field>
|
||||||
|
|
Loading…
Reference in New Issue