0

There are similar questions asked. But I tried all possible solutions for those questions and none of them worked. I have a dojo modal and I want to capture both the close event 'X' at the top right and also the 'escape' key press event. Below is my code.

<script>
    dojo.connect(dojo.byId("myDialog"),"onCancel", function(){
        alert("Hi");
    });
    document.body.addEventListener('keypress', function(e) {
          if (e.key == "Escape") {
            alert("Hi");
          }
        });

</script>

<div class="myDialogClass" id="myDialog" name="myDialog" role="dialog" style="display:none" dojoType="dijit/Dialog"  closeOnTimeOut="false" parseOnLoad="true" title="Title">
</div>

I tried all the below solutions, and none of them worked

1. dojo.connect(dojo.byId("myDialog"),"onHide"
 2. dojo.connect(dojo.byId("myDialog"),"hide"
 3. myDialog.connect(myDialog, "hide", function(e){
        dijit.byId("user_submit").destroy();  });
 4. <script type="dojo/method" event="onClose"> console.log('closed')
    </script>*, *<script type="dojo/method" event="onCancel">
    console.log('closed') </script>
 5. var myDialog = new Dialog({    id: "myDialogId1",    onHide:
     function() {
           myDialog.destroy()    }
});

Any help is much appreciated.

1 Answer 1

0

I got the issue fixed using the below code.

require(["dojo/on", "dojo/ready", "dijit/registry"], function(on, ready, registry) {

    ready(function() {
        var d = dijit.byId("myDialog")
        d.on('hide', function() {
            console.log('closed');
            location.reload();
        });
    });

});

Not the answer you're looking for? Browse other questions tagged or ask your own question.