tom-select icon indicating copy to clipboard operation
tom-select copied to clipboard

[Bug]: initialize event not fired under specific circumstances as it seems

Open bytes-commerce opened this issue 1 year ago • 4 comments

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)

bytes-commerce avatar Nov 17 '23 11:11 bytes-commerce

Hmm, looks like maybe the event listener is being added after Tom Select is already initialized?

oyejorge avatar Nov 17 '23 16:11 oyejorge

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).

bytes-commerce avatar Nov 17 '23 20:11 bytes-commerce

Also, modifying the JsFiddle does not lead to another result.

bytes-commerce avatar Nov 17 '23 20:11 bytes-commerce

I changed some things on your example, try it out here

pvh-archifact avatar Nov 20 '23 11:11 pvh-archifact

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

github-actions[bot] avatar Mar 20 '24 01:03 github-actions[bot]