Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent window from closing on ESC extjs 4

I am stuck with one problem with one problem in stop the window from closing using ESC button.

The window gets closed as soon as I click the ESC button from my keyboard. I want the window should not close, instead it should prompt a message box asking 'YOU REALLY WANTS TO close' with two button yes or cancel

If person click yes button the the window should destroy and else the window should be as it is.

but don't know why the window is getting close on ESC press.

I am prompting message as the user click the esc button using below code

listeners: {
        show : function(win) {
          Ext.create('Ext.util.KeyNav', win.getEl(), {
            "esc" : function(e){
              alert('hi.. closing');
              win.hide();
            },
            scope: win
          });
        }
      }

now I want the message box to be appeared and based on the person answer things to be happend. any help ??

like image 713
Yogendra Singh Avatar asked Mar 04 '12 06:03

Yogendra Singh


1 Answers

There is very convenient onEsc function in window's config. Use it this way:

onEsc: function() {
    var me = this;
    Ext.Msg.confirm(
        'Closing confirmation',
        'YOU REALLY WANTS TO close',
        function(btn) {
            if (btn === 'yes')
                me.hide();
        }
     );
},

Here is live example.

like image 87
Molecular Man Avatar answered Oct 31 '22 19:10

Molecular Man