Search code examples
extjsextjs5extjs6-classic

How to fire an click event on the "OK" of Ext.Msg.alert?


After a form is saved successfully, an alert is fired and looks as the following:

Ext.Msg.alert('Success','Changes saved successfully');

enter image description here

How to fire an click event on the "OK" through javascript or extjs?

Refer to Programmatically call handler of a button event?, the following worked, however it looks a bad idea to find out the button-id that is generated by extjs.

var btn = Ext.getCmp('button-id');
var e = null; // we don't have any event, so let's use nothing
Ext.callback(btn.handler, btn.scope, [btn, e], 0, btn);

Solution

  • You can go down the component hierarchy from Ext.Msg (or whatever none-singleton instance of message box you are using). In ExtJS 6 classic, the way to go would be:

    Ext.Msg.down('button[itemId=ok]').click();
    

    I have made a small fiddle that shows the working solution.