pstanoev / simple-svelte-autocomplete

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

valueFieldName doesnt work #217

Open gponty opened 7 months ago

gponty commented 7 months ago

Hi :)

<script>
     import AutoComplete from "simple-svelte-autocomplete"

let selectedColor;
async function searchColor(keyword) {
  return [
        { id:1,color:"White" },
        { id:2,color:"Black" },
  ]
}
</script>

<AutoComplete
    searchFunction={searchColor}
    bind:selectedItem={selectedColor}
        labelFieldName="color"
        valueFieldName="id"
        onChange="{() => console.log(selectedColor)}"
/>

selectedColor = { id:1,color:"White" } instead of selectedColor = 1

REPL : https://svelte.dev/repl/b6a3421f9a574c148ba740d88e75ab81?version=4.2.9

Thank you

Astronautilus14 commented 7 months ago

Yes this is wrong in the readme I think, you should do bind:value={selectedColor} instead.

This example in the read me makes it look like you can use valueFieldName with selectedItem

gponty commented 7 months ago

Thank you @Astronautilus14