Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add click listener on on button in Ext.window.MessageBox

I am creating dinamically a message box (Ext.window.MessageBox)

var msgBox = Ext.create('Ext.window.MessageBox', {
       title: '',
       //message in window
       msg: 'message text',
       icon: 'WARNING',
       //buttons
       buttons: 'OKCANCEL',
       //onclick funciton
       fn: myfunc
 });

I am adding OK and Cancel buttons. Is it possible to add click listener on the OK button so that I can do my stuff only when this OK button is pressed?

Also is it possible to add specific ids to the OK and Cancel buttons so that I can distinguish them more easily, instad of using the pregenrated ids from ExtJS?

like image 955
Vlad Avatar asked Nov 27 '12 21:11

Vlad


1 Answers

You may use the following construction instead:

Ext.MessageBox.show({
    title: "",
    msg: "message text",
    icon: Ext.MessageBox.WARNING,
    buttons: Ext.MessageBox.OKCANCEL,
    fn: function(buttonId) {
        if (buttonId === "ok") {
            // do on OK pressed
        }
    }
});

Here the first argument in the fn handler is a string value of pressed button.

DEMO: http://jsfiddle.net/xj9qY/

like image 69
VisioN Avatar answered Sep 24 '22 14:09

VisioN