The running example is about sending a submit event to a form. I needed to do that for a demo of user interface testing via CasperJS. And, unfortunately, the Form#submit method does not send that event on most web engines.
Example: submit events are created via the Event constructor.
Example: The constructor for interface Event has the following Interface Definition Language (IDL) signature:
Constructor(DOMString type, optional EventInit eventInitDict)Optionally, EventInit can be passed in as an object and configures whether an event bubbles or is cancelable. It is defined in IDL as:
dictionary EventInit { boolean bubbles; boolean cancelable; };
Example: The following code triggers a submit event:
var elem = document.getElementById('myForm'); var event = new Event('submit'); // (*) elem.dispatchEvent(event);Line (*) is equivalent to:
var event = new Event( 'submit', { bubbles: false, cancelable: false });
On browsers that don’t support event constructors, you have to resort to the legacy document.createEvent().