Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If user hits ESC or ENTER in editing Form input elements (select, autocomplete, ..) browser closes modal window.
How to disable closing modal window with ESC and ENTER buttons?
Comments
Comment #1
alunyov CreditAttribution: alunyov commentedI had similar kind of a problem. I had to disable closing modal popup by pressing ESC.
In my case solution was adding unbind for modalEventEscapeCloseHandler for page where I was going to get modal popup:
Comment #2
joelstein CreditAttribution: joelstein commentedI would also like to see some way to disable at least the ESC behavior. For example, if using Fieldable Panels Panes and Panels IPE to edit content in a modal, there are several scenarios where typing the escape key would be suitable (to close a Media browser or a Linkit modal), but this also causes the modal to disappear. And anyway, if the user has entered lots of data on the form, accidentally clicking ESC still closes the modal with no prompt and no way to recover what's lost.
I almost wrote a patch for this, but then came up with this method in my theme:
Still, I would prefer that there was a JS setting that would allow us to bypass this behavior, such as
Drupal.settings.CToolsModal.escapeClose = false
or something.