pstanoev / simple-svelte-autocomplete

Simple Autocomplete / typeahead component for Svelte
http://simple-svelte-autocomplete.surge.sh/
MIT License
468 stars 79 forks source link

Objects selection does not accept value binding #171

Open jfowl opened 2 years ago

jfowl commented 2 years ago

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 :)

pstanoev commented 2 years ago

Can you try with the text parameter to initialize it?

jfowl commented 2 years ago

Hey @pstanoev, I apologize for not answering, currently too busy working on my thesis. I will get back to this eventually. :)

jfowl commented 2 years ago

Okay, I can't find the energy to re-test this currently, sorry :/

Feel free to close this issue :)