0

I have a dialog box #acronymPickerDialog that gets destroy on click of the #cancelBtn. however now I notice that when I click the escape button although the box appears to close, it still remains pasted at the bottom of the page. In other words, it's not getting destroy onClick of the Esc button. I need code that destroys this dialog box when I click on the Esc key.

It's set up like this right now:

events: {
    "click #okBtn": "selectAcronym",
    "click #cancelBtn": "closeAcronymPicker"
},


closeAcronymPicker: function () {  
    this.destroy();
}
kryger
  • 12,906
  • 8
  • 44
  • 65
  • Find a script on Stackoverflow that may help you out: http://stackoverflow.com/questions/4301859/close-dialogbox-when-click-escapeesc-in-gwt[link] – Paul Nov 11 '14 at 20:36

1 Answers1

1

Try remove() instead of destroy(). Something like this:

document.addEventListener('keyup', function (event) {
  if ( event.keyCode == 27 )   {
     document.getElementById('your-dialog-box').remove()
  }
})
elzi
  • 5,442
  • 7
  • 37
  • 61
  • `keyCode` is now deprecated use `e.key === "Escape"` instead. cf [this answer](https://stackoverflow.com/a/3369624/13448212) – Ostas Mar 27 '23 at 07:04