[pgAdmin][RM4610] Enter key on search box for dropdown intercepted by modal

Aditya Toshniwal <[email protected]>
Newsgroups gmane.comp.db.postgresql.pgadmin.devel
Message-ID <CAM9w-_nQiNGS-sw6yFdBkKzvzH8k4EKzxxQ6xtVocqFzan62Mg@mail.gmail.com>
Hi Hackers,

Attached is the patch to suppress enter key events from the select2 boxes
when in an alertify dialog.
Alertfiy takes reads the enter keyup event and triggers Save.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Sr. Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"
RM4610.patch (application/octet-stream, 1 KB)
diff --git a/web/pgadmin/static/js/alertify.pgadmin.defaults.js b/web/pgadmin/static/js/alertify.pgadmin.defaults.js
index 592c1e566..954653d7b 100644
--- a/web/pgadmin/static/js/alertify.pgadmin.defaults.js
+++ b/web/pgadmin/static/js/alertify.pgadmin.defaults.js
@@ -463,5 +463,24 @@ define([
     reverseButtons: true,
   });
 
+  /* Suppress the enter key events occurring from select2 boxes
+   * so that the dialog does not close.
+   * Alertify listens to keyup events on the body element unfortunately
+   * instead of alertify dialog
+   */
+  $('body').off('keyup').on('keyup', function(ev){
+    if(ev.which === 13) {
+      let suppressForClasses = ['select2-selection', 'select2-search__field'];
+      let $el = $(ev.target);
+      for(let i=0; i<suppressForClasses.length; i++){
+        if($el.hasClass(suppressForClasses[i])){
+          ev.preventDefault();
+          ev.stopImmediatePropagation();
+          ev.stopPropagation();
+          break;
+        }
+      }
+    }
+  });
   return alertify;
 });
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.