Skip to content

Commit

Permalink
hide turbo frame error message when context changed (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni authored Oct 31, 2023
1 parent 7606205 commit 42c9c4d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.alert-message{
font-size: 16px;
margin: 0 10px;
text-align: center;
width: 100%;
}


Expand Down
9 changes: 2 additions & 7 deletions app/javascript/controllers/turbo_frame_error_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down

0 comments on commit 42c9c4d

Please sign in to comment.