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

element.dispatchEvent(new Event(event)) doesn't work #629

Open
r3tr0sp3c opened this issue Jun 29, 2023 · 1 comment
Open

element.dispatchEvent(new Event(event)) doesn't work #629

r3tr0sp3c opened this issue Jun 29, 2023 · 1 comment

Comments

@r3tr0sp3c
Copy link

r3tr0sp3c commented Jun 29, 2023

Here's a simple example:

document.getElementById("input-field1").addEventListener("cocoon:after-insert", () => {
      document.getElementById("input-field2").dispatchEvent(new Event("input"));
    })

The dispatchEvent doesn't work on any cocoon callback.

A workaround is to place the dispatchEvent inside a setTimeout function

document.getElementById("input-field1").addEventListener("cocoon:after-insert", () => {
  setTimeout(() => {
        document.getElementById("input-field2").dispatchEvent(new Event("input"))
      }, "5");
})

Not sure if that's an expected behavior or a bug.

@nathanvda
Copy link
Owner

The original javascript uses jquery to dispatch and handle events, so imho that is not compatible, but probably you are not using the "original" javascript (there is a version using "plain" javascript).

So assuming you are using that version, the events are ment to be handled on a container level, they will not be dispatched on any single input-field inside the form.

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

No branches or pull requests

2 participants