I'm working on building my template and have the initial steps down. I'm on Rails 7.0.2.4, turbo-rails 1.1.1, Bootstrap 5.
In my layouts template's I have the following:
= javascript_include_tag "application", data:{turbo:{track: "reload"}}, defer: true
Which links to my app/javascript/application.js, and the relevant parts here are:
import * as bootstrap from "bootstrap" var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) })
The second part above enabled Bootstraps tooltips.
Back in my template, I break it down into three Turbo Frames:
%turbo-frame{id: "main_frame", data:{turbo:{action: "advance"}}} .container-fluid .row.flex-nowrap .col-auto.col-md-3.col-xl-2.px-sm-2.px-0.bg-dark %turbo-frame{id: "sidebar", data:{turbo:{action: "advance"}}} .col %turbo-frame{id: "content", data:{turbo:{action: "advance"}}} = yield
First, there is the main_frame, which is then divided into a Sidebar and a Content frame. Clicking on links in the sidebar, which have date-turbo-frame: "content" attributes, swaps out the Content frame with that necessary content.
Now, on most full Content frames, the top of that frame has a navigation header which has a button on the left and right sides and text in the middle:
%turbo-frame{id: "content", data:{turbo:{action: "advance"}}} .row .d-flex .p-2 %a{href: path, data:{turbo:{frame: "content"}, bs:{toggle: "tooltip", placement: "bottom", title: "Back"}}, aria:{label: "Back"}} %i.bi.bi-arrow-left-circle-fill{aria:{hidden: "true"}} .flex-grow-1 // Some Text .p-2 %a{href: new_path, data:{turbo:{frame: "new"}, bs:{toggle: "tooltip", placement: "bottom", title: "New"}}, aria:{label: "New"}} %i.bi.bi-plus{aria:{hidden: "true"}}
When you navigate to this replaced Content, the tooltips do not work. However, when you do a FULL page reload via the browser, the tooltips are suddenly working because the code is in the head.
Is there a way I can get the frames to load the necessary Javascript?