simple-svelte-autocomplete icon indicating copy to clipboard operation
simple-svelte-autocomplete copied to clipboard

Objects selection does not accept value binding

Open jfowl opened this issue 2 years ago • 3 comments

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

jfowl avatar Apr 24 '22 22:04 jfowl

Can you try with the text parameter to initialize it?

pstanoev avatar Jun 01 '22 13:06 pstanoev

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

jfowl avatar Jul 04 '22 07:07 jfowl

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

Feel free to close this issue :)

jfowl avatar Aug 15 '22 22:08 jfowl