From 7689a51b1d95b71a13fe2bf56ee7f85a81bfb551 Mon Sep 17 00:00:00 2001
From: alexisben <alexiben7@gmail.com>
Date: Fri, 6 May 2022 17:45:29 +0200
Subject: [PATCH] Intercept enter keypress

---
 .../communication/unsplash/_selector.html.erb | 22 ++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/app/views/admin/communication/unsplash/_selector.html.erb b/app/views/admin/communication/unsplash/_selector.html.erb
index d23320f0c..a5e7b9ee9 100644
--- a/app/views/admin/communication/unsplash/_selector.html.erb
+++ b/app/views/admin/communication/unsplash/_selector.html.erb
@@ -103,13 +103,29 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
         data: {
           results: [],
           total: 0
-        }
+        },
+        isOpened: false
       }
     },
     mounted() {
       var modalElement = document.querySelector('#unsplashModal')
       this.modal = bootstrap.Modal.getOrCreateInstance(modalElement);
-      modalElement.addEventListener('show.bs.modal', this.search.bind(this))
+
+      modalElement.addEventListener('show.bs.modal', function (){
+        this.isOpened = true;
+        this.search.bind(this)
+      }.bind(this));
+
+      modalElement.addEventListener('hide.bs.modal', function() {
+          this.isOpened = false;
+      }.bind(this));
+
+      document.addEventListener("keydown", function(event) {
+        if (event.key === "Enter" && this.isOpened) {
+          event.preventDefault();
+          event.stopImmediatePropagation();
+        }
+      }.bind(this));
     },
     watch: {
       page(value) {
@@ -130,7 +146,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
             console.log(this.data)
           }
         }.bind(this);
-
+        
         xmlHttp.open( "GET", this.parameters.url + '&query=' + this.parameters.query + '&per_page=' + this.parameters.per_page + '&page=' + this.page + '&lang=' + this.parameters.lang, false );
         xmlHttp.send( null );
       },
-- 
GitLab