From 42c9c4db6256d16729dbd0d896087d2b4a66df1a Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Tue, 31 Oct 2023 17:24:21 +0100 Subject: [PATCH] hide turbo frame error message when context changed (#369) --- app/assets/stylesheets/components/alert.scss | 2 +- .../controllers/turbo_frame_error_controller.js | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/components/alert.scss b/app/assets/stylesheets/components/alert.scss index e68adc486..43ee5d21f 100644 --- a/app/assets/stylesheets/components/alert.scss +++ b/app/assets/stylesheets/components/alert.scss @@ -24,7 +24,7 @@ .alert-message{ font-size: 16px; margin: 0 10px; - text-align: center; + width: 100%; } diff --git a/app/javascript/controllers/turbo_frame_error_controller.js b/app/javascript/controllers/turbo_frame_error_controller.js index b19c63c12..782166bc5 100644 --- a/app/javascript/controllers/turbo_frame_error_controller.js +++ b/app/javascript/controllers/turbo_frame_error_controller.js @@ -34,18 +34,13 @@ export default class extends Turbo_frame_controller { Array.from(styles).forEach(e => el.removeChild(e)) let body = el.querySelector('h1') - let div = document.createElement('div') - div.className ="text-center" - div.innerHTML = (body ? body.innerText : el.innerHTML) - this.errorMessageTarget.firstElementChild.appendChild(div) + this.errorMessageTarget.firstElementChild.querySelector('.alert-message').innerHTML = (body ? body.innerText : el.innerHTML) $(this.errorMessageTarget).show() } #hideError(){ - let child =this.errorMessageTarget.firstElementChild let count = this.errorMessageTarget.firstElementChild.childElementCount - if(count === 2) { - child.removeChild(child.lastElementChild) + if(count !== 0) { $(this.errorMessageTarget).hide() } }