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] Error: Tom Select already initialized on this element #2623

Open
Bartheyrman22 opened this issue Mar 3, 2025 · 4 comments
Open
Labels
Autocomplete Bug Bug Fix Status: Waiting Feedback Needs feedback from the author

Comments

@Bartheyrman22
Copy link

Bartheyrman22 commented Mar 3, 2025

I get the following error message when moving a TomSelect [Autocomplete] in the DOM.
This after upgrading from 2.21.0 to 2.22.0 (and still present in 2.23.0)

Error connecting controller

 Error: Tom Select already initialized on this element
    TomSelect tom-select.ts:104
    _default_1_createTomSelect2 controller.js:372
    _default_1_createAutocomplete2 controller.js:296

The code I use to move the element:

    filterModal.querySelector('.modal-body').appendChild(autocompleteElement)
    document.querySelector('body').appendChild(filterModal)
@Bartheyrman22 Bartheyrman22 added the Bug Bug Fix label Mar 3, 2025
@Bartheyrman22 Bartheyrman22 changed the title [Autocomplete] [Autocomplete] Error: Tom Select already initialized on this element Mar 3, 2025
@Kocal
Copy link
Member

Kocal commented Mar 3, 2025

I'm looking at the diff between v2.12.0 and v2.22.0, and I'm not sure to see how switching from item.text to const labelField = commonConfig.labelField ?? 'text'; item[labelField] could introduce an issue.

Are you sure you only updated symfony/ux-autocomplete? Did you updated @hotwired/stimulus or tom-select as well?

Can you provide us a reproducer? 🙏🏻

@Kocal Kocal added Status: Waiting Feedback Needs feedback from the author and removed Status: Needs Review Needs to be reviewed labels Mar 3, 2025
@Bartheyrman22
Copy link
Author

I did some more tests, and it just happens from time to time. So I believe indeed version independant. Probably some race condition?
At the moment without side effects and maybe not related to this bundle but to the stimulus bundle.
I found this: hotwired/stimulus#549
So maybe we should check before attaching a second time and do nothing?

I only updated symfony/ux-autocomplete by using composer require symfony/ux-autocomplete 2.22.0

@FluffyDiscord
Copy link

FluffyDiscord commented Apr 2, 2025

I have this same issue. It happens when I send Symfony form with autocomplete and if it has errors and returns the same page with status code 422, this error happens. The autocomplete still works and what not, but its spamming errors in console.

I have not used any previous versions of UX, I just upgraded Symfony and added this as a replacement for old Select2 bundle.

Using webpack

@FluffyDiscord
Copy link

@Bartheyrman22 I found out that someone had been initializing Turbo in the wrong place. It should be included in and it was in the . After fixing that, this error went away and select works as intended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Autocomplete Bug Bug Fix Status: Waiting Feedback Needs feedback from the author
Projects
None yet
Development

No branches or pull requests

4 participants