Inserting and showing Bootstrap modal within a Turbo Frame (Rails)
Today I worked out an example of using the Bootstrap modal component in a Turbo Frame.
This link triggers the response with the Turbo Frame containing the Boostrap modal. It is not inside a Turbo Frame, so the data-turbo-frame attribute is used to specify which Turbo Frame is the target:
This is the target Turbo Frame to be replaced:
This is the ERB with the replacement Turbo Frame which has the Bootstrap modal:
The problem with this is the Bootstrap modal will not show itself just from being inserted in the DOM as a Turbo Frame.
To accomplish that, add an event listener in application.js that listens to the "turbo:frame-load" event and shows the modal:
With this, the modal will show itself when it’s inserted in the DOM as a Turbo Frame.