simple-svelte-autocomplete
simple-svelte-autocomplete copied to clipboard
Objects selection does not accept value binding
A bit hard to describe, so here is some code to show it:
This is my component (let's call it ResolutionSelector
) which wraps AutoComplete
<script lang="ts">
import AutoComplete from 'simple-svelte-autocomplete';
async function search(query: string) {
// actually there is an api call here, but whatever:
return [{number: "2022.4.2.34", text: "we vote to kick Bob"}];
}
export let selectedResolution = "2022.4.2.34";
</script>
<AutoComplete
searchFunction={search}
localFiltering={false}
create={false}
valueFieldName="number"
labelFieldName="number"
bind:value={selectedResolution}
>
I bind to my components selectedResolution
from outside and expect that it is reflected in AutoComplete
's value.
But it does not react to setting it to a string like "-none-"
or anything else. Binding to AutoComplete
's placeholder
works, though.
I suspect the duality of using objects for the choosable items, but exposing just one property of them as the selected value, might be the culprit. I'm not certain on this, so maybe you might be able to spot the real issue :)
Can you try with the text
parameter to initialize it?
Hey @pstanoev, I apologize for not answering, currently too busy working on my thesis. I will get back to this eventually. :)
Okay, I can't find the energy to re-test this currently, sorry :/
Feel free to close this issue :)