tom-select
tom-select copied to clipboard
[Bug]: initialize event not fired under specific circumstances as it seems
Bug description
initialize
seems not to be fired when used in a specific integrational way.
I use Tom Select trough direct integration in EasyAdmin bundle for Symfony . I have this Javascript to detect any initialization of any of the TS forms:
const tsControllers = document.querySelectorAll('.ts-control');
console.log(tsControllers);
const eventNames = ['initialize', 'load', 'change', 'focus', 'blur'];
tsControllers.forEach(function(elem) {
eventNames.forEach((name) => {
elem.addEventListener(name, function(event) {
console.log('hey I am done', name, event);
});
});
});
When I am reloading my Frontend page, this JS is executed. Its sitting inside an document.addEventListener('DOMContentLoaded', function () {
stack, because otherwise it will not be able to find the nodes, as the DOM is simply not there at the time the page is being rendered.
However, I do not see any remarks for initialized (or changed for the matter) being fired, when reloading the page (or retrospectively change a value).
The only events that are however firing are change
and blur
. In the JsFiddle, Blur is not even fired, too.
Am I doing something wrong in the execution, or is this a bug?
Expected behavior
All events are properly fired in the given situation.
Steps to reproduce
I have created my attempt here with plain vanilla JS.
https://jsfiddle.net/gvw2s0Le/
Additional context
- OS: Linux
- Browser Firefox
- Version 119.0 (64-Bit)
Hmm, looks like maybe the event listener is being added after Tom Select is already initialized?
Thats my guess as well, but I can't get around the point in time when this happens + when my code is fired. Additionally, since its a packed JS, I cannot just shoot my stuff inbetween. :/ The problem is also existent if I force my code to be executed before the TomSelect init (I believe, at least).
Also, modifying the JsFiddle does not lead to another result.
I changed some things on your example, try it out here
This issue has not been active in 120 days and has been marked "stale". Remove stale label or comment or this will be closed in 15 days