The way Mendix handles clicks on a button is a bit complicated. Below you can find a snippet from a hotkey widget that we made, which should appear in the appstore in the not to far future.
The trick is to call the action method on the button that you would like to click.
// retrieve the button using a CSS selector. this.selector is a selector string, e.q. ".search-button"
var button = dojo.query(this.selector)[0];
// retrieve the dijit widget that belongs to this button
var widget = dijit.byId(button.id);
// execute the action that is triggert when a user clicks the button
// if the button is a datagrid buttont the action method expects a parameter
widget.action({
currentTarget : widget.domNode
});
Hop this helps, if you have questions about it, let me know.
Kilian Croese, Capgemini
You don't need the two-step finding of the button. dojo.query(".formsubmit").dispatchEvent(evt)
should work.
try "click" instead of "mousedown"
Actually, I could just do dojo.query(".formsubmit")[0].dispatchEvent(evt);
But the reason I grabbed the Id is because query returns an array of results so you can't dispatchEvent()
Again, it still doesn't work. Also there is no click event on the DIV element. The event is on mousedown when I actually click on the button.
I even tried to focus on the button and simulate the Enter key but it doesn't work either! What is preventing this from working:
//Focus - works!
buttonid = dojo.query(".formsubmit").attr("id")[0];
document.getElementById(buttonid).focus();
//Create Enter event
evt1 = document.createEvent("KeyboardEvent");
evt1.initEvent("keydown", true, true, window, false, false, false, false, 13, 0);
//Execute - doesn't work!
document.getElementById(buttonid).dispatchEvent(evt1);
The ".formsubmit" button has a keyup/keydown event so I have no idea why those won't trigger either.