ux icon indicating copy to clipboard operation
ux copied to clipboard

[Autocomplete] Reset TomSelect when updating controller attributes

Open pierredup opened this issue 1 year ago • 0 comments

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.

pierredup avatar Feb 15 '24 19:02 pierredup