bitbldr

bitbldr

Phoenix LiveView and Bootstrap tooltips

Hello!

I’m having trouble using Bootstrap tooltips inside a Phoenix LiveView. I have verified that the tooltips work just fine on the same page outside of the LiveView in the eex template, but when placed inside of a LiveView render function they do not seem to work. I’m wondering if this is something related to browser events not making their way to the underlying Popper.js listeners due to Phoenix or if it is simply not possible to do something like this inside of LiveView, which would be a shame because LiveView has been wonderful in so many other ways.

Here is an abbreviated snippet of my code:

  def render(assigns) do
    ~L"""
        ...


        <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="Tooltip on top">
          Tooltip on top
        </button>

      ...
      """

What I have tried so far without success…

  1. Standard tooltip initialization from the eex template
  <body>
    ...

    <script>
    $(function () {
      $('[data-toggle="tooltip"]').tooltip();
    });
    </script>
  </body>
  1. Phoenix hook using phx-hook=“TooltipInit”
export const TooltipInit = {
  mounted() {
    const id = this.el.getAttribute('id');
    $('#' + id).tooltip();
  },
};

  1. Adding script tag with initialization directly in the LiveView render
  2. Calling initialization directly in browser console
> $('[data-toggle="tooltip"]').tooltip();
w.fn.init [button.btn.btn-secondary]

The codebase heavily leverages bootstrap for styling and themes, so we aren’t really in a position to switch away from bootstrap as our main framework. Any help or advice would be greatly appreciated.

Thanks!

Marked As Solved

mindok

mindok

Have you tried adding phx-update="ignore" to your button? Liveview manipulates the DOM so clashes with any other JS trying to manipulate the DOM. phx-update="ignore" tells LiveView not to mess with that element and its children.

Also Liked

AndyL

AndyL

Perhaps this blog post on ‘Bootstrap Native’ would be useful…

I’m curious to learn what you find please report back on your progress!!

Last Post!

bitbldr

bitbldr

Thanks everyone! Adding phx-update="ignore" to the button’s parent div worked like a charm.

I quickly tried using BSN as well, but I couldn’t get it working and quickly gave up given the other solution. Maybe sometime in the future we can switch over or just upgrade to BS 5 with no jquery dependency :grinning:

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement