Search code examples
buttondojodijit.form

set a click event dynamically to dojo button


I m trying to set a on click event dynamically to a dijit/form/Button. But, the method I m trying doesn't seem to work.

<button id = "newActButton" data-dojo-type="dijit/form/Button"
    type = "button" 
    data-dojo-props="iconClass: 'newActButtonIcon', label: 'New Act'"></button>


dijit.byId("newActButton").set("onClick", newActButtonOnClick());

I have a function newActButtonOnClick(), which I want to fire.


Solution

  • You may try something like this:

    require(["dojo/on", "dojo/dom", "dojo/domReady!"],
        function(on, dom) {
            var newActButton = dom.byId("newActButton");
    
            on(newActButton, "click", newActButtonOnClick);
    });
    

    Here's tutorial

    jsfiddle