diff --git a/app/views/admin/communication/unsplash/_selector.html.erb b/app/views/admin/communication/unsplash/_selector.html.erb index 73c95967cd317f4ca648477778c4868a0451f7b2..2bcec6fb8d1c021fd74c60fa97b0801b1fe88117 100644 --- a/app/views/admin/communication/unsplash/_selector.html.erb +++ b/app/views/admin/communication/unsplash/_selector.html.erb @@ -107,13 +107,29 @@ path = admin_communication_unsplash_path(website_id: nil, format: :json) 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,6 @@ path = admin_communication_unsplash_path(website_id: nil, format: :json) xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { this.data = JSON.parse(xmlHttp.responseText); - console.log(this.data) } }.bind(this);