Skip to content

[Autocomplete] Attempting a simpler "reset" of items #1290

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

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Nov 20, 2023

Q A
Bug fix? yes
New feature? no
Issues Possibly #1290 (need to check and remove data-live-ignore), fixes #1261 possibly #1241 possibly #909
License MIT

Tomselect is a real pain in the butt. When you select an option, it re-orders the option elements and uses the elements themselves internally to remember which one is selected. It plays poorly with LiveComponents, which is why we added the MutationObserver logic. However, at least in one straightforward case that I had today, when you selected a new item, the new value was being lost. This will only get worse when Turbo 8 adds morphing.

This PR attempts to simplify: when needed, completely destroy TomSelect and recreate it. It seems to work well, but 2 tests are failing. And I'm pulling my hair out - so it may not even be fixable. No matter what I try, when I reinitialize TomSelect on a set of HTML that has been reordered, it gets confused. It's as if it has a static cache somewhere that I can't find...

@weaverryan
Copy link
Member Author

Related: orchidjs/tom-select#666

I simply can't figure out how to make TomSelect keep the selected option value.

@weaverryan weaverryan force-pushed the autocomplete-simpler-reset branch from 43442fe to 985445a Compare January 21, 2024 21:32
@weaverryan
Copy link
Member Author

SO happy to say that this is ready 😅.

tl;dr TomSelect rearranges the <option> elements. If something "morphes" the <option> element like LiveComponents (or Turbo 8) does, TomSelect can't handle this. This PR removes morphing for the<option> elements for Autocomplete and fixes & improves how we reinitialize TomSelect if the option elements DO change.

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

Successfully merging this pull request may close these issues.

[LiveComponet] [Autocomplete] Bug when combining live with autocomplete select field
1 participant