Open zogs opened 1 year ago
Similar issue here. onChange shouldn't trigger when the bound value is set externally
I'm running into the same issue.
In this case I'm usingbind:selectedItem
in combination with onChange
that causes a page reload, which causes onChange
to fire again and enter a loop.
Happy to put a PR together if there's appetite from the maintainer for this change, @pstanoev?
In the meantime I've found a workaround for my issue using beforeChange
instead of onChange
in this manner:
<AutoComplete
beforeChange={(oldItem, newItem) => {
filter.selectedCountry = newItem;
dispatch('change');
}}
bind:selectedItem={filter.selectedCountry}
items={filter.countryOptions}
labelFieldName="name"
valueFieldName="iso_code"
/>
The call to dispatch('change')
is what eventually triggers a page reload.
Part of the problem is also in this issue : https://github.com/pstanoev/simple-svelte-autocomplete/issues/36
In my opinion onChange shoud not be trigger by a external assignment, only when user manually change the field
This special case that is causing me trouble : I need to persist the object in DB when user change the value, then the value gets update from the DB, but it's triggering a onChange event causing a recursive loop ...