Sanity filter on change

This commit is contained in:
Adria Navarro 2023-10-03 13:10:53 +02:00
parent 9b14f50e8f
commit 0702bc6c33
1 changed files with 12 additions and 1 deletions

View File

@ -5,6 +5,7 @@
import { API } from "api" import { API } from "api"
export let value = null export let value = null
export let multiple = false
$: fetch = fetchData({ $: fetch = fetchData({
API, API,
@ -17,11 +18,21 @@
}) })
$: options = $fetch.rows $: options = $fetch.rows
function onChange(e) {
const val = e.detail
if (!val) {
value = val
} else {
value = Array.isArray(val) ? val : [val]
}
}
</script> </script>
<Select <Select
value={multiple ? value : value[0]}
autocomplete autocomplete
bind:value on:change={onChange}
{options} {options}
getOptionLabel={option => option.email} getOptionLabel={option => option.email}
getOptionValue={option => option._id} getOptionValue={option => option._id}