pstanoev / simple-svelte-autocomplete

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

valueFieldName not working #202

Open stinkokenzo opened 1 year ago

stinkokenzo commented 1 year ago
const countries = [
    { _id: 1, name: "America" },
    { _id: 2, name: "Canada" },
    { _id: 3, name: "China" },
    { _id: 4, name: "France" },
    { _id: 5, name: "Germany" },
    { _id: 6, name: "India" },
    { _id: 7, name: "Italy" },
    { _id: 8, name: "Japan" },
    { _id: 9, name: "Mexico" },
    { _id: 10, name: "Russia" },
    { _id: 11, name: "Spain" },
    { _id: 12, name: "United Kingdom" },
    { _id: 13, name: "United States" },
]

let country;

<AutoComplete
    name="country"
    placeholder="Select a Country"
    items={countries}
    bind:selectedItem={country}
    labelFunction={(item) => item.name}
    valueFieldName="_id"
/>

The value submitted by the form is the name of the Country and not the _id . Also tried with valueFunction but same issue.

gponty commented 5 months ago

Same problem here