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

alunyov’s picture

I 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:

      drupal_add_js('
      jQuery(document).ready(function(){
        jQuery(document).unbind("keydown", modalEventEscapeCloseHandler);
      });
      ', 'inline');
joelstein’s picture

Version: 7.x-1.4 » 7.x-1.x-dev

I 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:

/**
 * Override Ctools modal content function to prevent closing the modal with
 * the escape key.
 */
Drupal.CTools = Drupal.CTools || {};
Drupal.CTools.Modal = Drupal.CTools.Modal || {};
var modalContent = Drupal.CTools.Modal.modalContent;
Drupal.CTools.Modal.modalContent = function(content, css, animation, speed, modalClass) {
  modalContent(content, css, animation, speed, modalClass);
  $(document).unbind('keydown', modalEventEscapeCloseHandler);
}

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.