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

[Autocomplete] Reset TomSelect when updating controller attributes #1505

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from

Conversation

pierredup
Copy link
Contributor

@pierredup pierredup commented Feb 15, 2024

Q A
Bug fix? yes
New feature? no
Issues Fix #1500
License MIT

When using remote data for Autocomplete, the mutation observer is not started, so the select cannot be reset when some options change (E.G when limiting the options returned after selecting other options using extra_options from #1322).

Instead, we start the mutation observer when using remote data. When the observer runs and checks if the options have changes, we explicitly set the areOptionsEquivalent to true, since the page will just render an empty select. We also check if any of the data-autocomplete attributes changes and forces a reset (E.G using extra_options, the data-autocomplete-url value can be different when using extra options, so we reset the select when this attribute changes).

This fixes only one of the issues from #1500, I'll investigate the other issues and create separate PRs.

@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Feb 15, 2024
@@ -123,7 +126,6 @@ class default_1 extends Controller {
this.element.innerHTML = currentHtml;
this.initializeTomSelect();
this.tomSelect.setValue(currentValue);
this.startMutationObserver();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The this.initializeTomSelect() call 2 lines above already starts the mutation observer (only under certain conditions, E.G when not using remote data). So this call incorrectly starts the mutation observer in the cases when it shouldn't run, which is why I removed the call here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Autocomplete][LiveComponent] Select box doesn't reset when used in a live component
3 participants