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] and [LiveComponent] don't play well together #407

Closed
janklan opened this issue Aug 6, 2022 · 3 comments · Fixed by #418
Closed

[Autocomplete] and [LiveComponent] don't play well together #407

janklan opened this issue Aug 6, 2022 · 3 comments · Fixed by #418

Comments

@janklan
Copy link
Contributor

janklan commented Aug 6, 2022

I noticed when the UX Autocompleter is part of the form and the form is rendered as a live component following https://symfony.com/bundles/ux-live-component/current/index.html#forms, the UX Autocompleter disappears once the component refreshes.

I made a minimal PoC site to demo the problem: https://github.com/janklan/symfony-ux-playground/tree/autocompleter-and-form-structure

This is what is happening:

2022-08-06 14 42 41

@maartendekeizer
Copy link
Contributor

Hit the same bug today. It will also happens when you change another field, in your example the Name field for example.
It looks like the new autocomplete is found by Stimilus and connected to the correct element

image

@janklan
Copy link
Contributor Author

janklan commented Aug 7, 2022

Hit the same bug today. It will also happens when you change another field

Yes, any time the live component re-renders, the autocomplete function is lost, no matter the cause for the re-render.

It looks like the new autocomplete is found by Stimilus and connected to the correct element

Stimulus knows about everything, but is told to do nothing.

I fixed it and I have a gif to prove it!

2022-08-08 07 37 05

Note author is the original, and author2 in an umapped field that uses my patched controller.

weaverryan added a commit that referenced this issue Aug 9, 2022
…nklan)

This PR was merged into the 2.x branch.

Discussion
----------

Unset TomSelect after destroying the Stimulus Controller

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       | [407](#407)
| License       | MIT

Sometimes Stimulus re-uses an instance of a controller after it's destroyed and re-created - for example when a Live Twig Component re-renders. Without unsetting the variable, [connect() method thinks TomSelect is already in place, and does nothing](https://github.com/symfony/ux/blob/2.x/src/Autocomplete/assets/src/controller.ts#L21-L25).

Commits
-------

01916e6 Unset tomSelect after destroying the instance
symfony-splitter pushed a commit to symfony/ux-autocomplete that referenced this issue Aug 9, 2022
…nklan)

This PR was merged into the 2.x branch.

Discussion
----------

Unset TomSelect after destroying the Stimulus Controller

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       | [407](symfony/ux#407)
| License       | MIT

Sometimes Stimulus re-uses an instance of a controller after it's destroyed and re-created - for example when a Live Twig Component re-renders. Without unsetting the variable, [connect() method thinks TomSelect is already in place, and does nothing](https://github.com/symfony/ux/blob/2.x/src/Autocomplete/assets/src/controller.ts#L21-L25).

Commits
-------

01916e6 Unset tomSelect after destroying the instance
@weaverryan
Copy link
Member

Re-opening - this is kind of a duplicate of #354, but we can close when live works well with autocomplete

@weaverryan weaverryan reopened this Aug 9, 2022
jameswebapp added a commit to jameswebapp/ux that referenced this issue Aug 1, 2023
…nklan)

This PR was merged into the 2.x branch.

Discussion
----------

Unset TomSelect after destroying the Stimulus Controller

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Tickets       | [407](symfony/ux#407)
| License       | MIT

Sometimes Stimulus re-uses an instance of a controller after it's destroyed and re-created - for example when a Live Twig Component re-renders. Without unsetting the variable, [connect() method thinks TomSelect is already in place, and does nothing](https://github.com/symfony/ux/blob/2.x/src/Autocomplete/assets/src/controller.ts#L21-L25).

Commits
-------

01916e6 Unset tomSelect after destroying the instance
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 a pull request may close this issue.

3 participants