Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onChange should only trigger by user action #198

Open
zogs opened this issue Feb 11, 2023 · 3 comments
Open

onChange should only trigger by user action #198

zogs opened this issue Feb 11, 2023 · 3 comments

Comments

@zogs
Copy link

zogs commented Feb 11, 2023

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 ...

@Blitzlord
Copy link

Similar issue here. onChange shouldn't trigger when the bound value is set externally

@rornic
Copy link

rornic commented Jun 12, 2023

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.

@DavidBruant
Copy link

Part of the problem is also in this issue : #36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants