Search code examples
dojodialogkeypress

Disable the escape key in dojo


I have a requirement to disable the escape key when the dialog is open.currently when i click the escape button the dialog closes and the transaction is submitting.I tried the following code snippet but its not working chrome.

                    dojo.connect(dialog, "onKeyPress", function(e){ 
                    var key = e.keyCode || e.charCode; 
                    var k = dojo.keys; 

                    if (key == k.ESCAPE) { 
                         event.preventDefault();

                     d.stopEvent(event);
                    } 
                    }); 

Could you please help on this..i have searched a lot and havent found a suitable solution for my problem. Thanks inadvance..


Solution

  • Dojo uses the _onKey event for accessibility. You can override it by using:

    dialog._onKey = function() { }
    

    I wrote an example JSFiddle, hitting the Escape key should not work anymore.