Last active
January 15, 2023 07:08
-
-
Save makrmark/75363a9bb99fd935c5705d9b7a1e347e to your computer and use it in GitHub Desktop.
How to respond to Bootstrap (5) events from within Rails Stimulus Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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