Skip to content

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

Description

@r3tr0sp3c

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions