Skip to content

Instantly share code, notes, and snippets.

@makrmark
Last active January 15, 2023 07:08
Show Gist options
  • Save makrmark/75363a9bb99fd935c5705d9b7a1e347e to your computer and use it in GitHub Desktop.
Save makrmark/75363a9bb99fd935c5705d9b7a1e347e to your computer and use it in GitHub Desktop.
How to respond to Bootstrap (5) events from within Rails Stimulus Controller
import { Controller } from "@hotwired/stimulus"
import { Modal } from "bootstrap"
// Connects to data-controller="remote-modal-events"
export default class extends Controller {
connect() {
let thisController = this
// The listener for the Bootstrap event
this.element.addEventListener('hide.bs.modal', function (event) {
thisController.clearModalContents();
})
}
// clear the contents using the turbo-frame id
clearModalContents() {
let content = document.querySelector("#remote_modal_content")
content.innerHTML = '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment