Search code examples
javascriptjqueryenyo

Trigger a button click on a moon.Button or moon.IconButton with jQuery/Javascript directly


I know the click action can be triggered by assigning ontap a specific function like so:

{
kind: "moon.Button",name :"search_button",  
content : "Search" , ontap : "searchAction", classes: "menu-button-style"
}

. . .

searchAction : function(){  //do some stuff on click}

I've tried

$('#id_of_my_button').click();
$('#id_of_my_button').trigger('click');

and none of those seem to work.

simplified jsFiddle

Any ideas


Solution

  • Here, try this:

    http://jsfiddle.net/Djspaceg/2AWb5/6/

    Enyo has a global handle (enyo) you can use if you need to access any part of its structure. It's not recommended for use from within our app, since it breaks encapsulation, but since you're already outside enyo (by using jQuery or plain JavaScript) I don't see as much harm.

    function TapThat() {
        // 'enyo' is the global namespace.
        // The '$' refers to the children of the object/kind.
        enyo.$.tappyButton.tapAction();
    }