Sebb
I have a two level hierarchy that I want to render in a bootstrap accordion.
It looks like this:
first-level-item-text-1
second-level-item-text-1-1
second-level-item-text-1-2
first-level-item-text-1
second-level-item-text-2-1
...
Normally I would put phx-update="ignore" on the accordion, to avoid that it is being closed on each render, but I can’t do that because I want to change the data that is displayed in a liveview - Is there a way to do that?
here is some code
<!-- cant put phx-update=ignore here -->
<div class="accordion accordion-flush p-1" id="blockAccordion">
<%= for first_level_item in first_level_items %>
<div class="accordion-item">
<h2 class="accordion-header">
<button data-bs-target="#flush-collapse-<%= first_level_item.id %>">
<%= first_level_item.text %>
</button>
</h2>
<div id="flush-collapse-<%= first_level_item.id %>" class="accordion-collapse collapse"
data-bs-parent="#blockAccordion">
<div class="accordion-body p-0 m-0">
<ul class="list-group list-group-flush">
<%= for second_level_item <- first_level_item.second_level_items do %>
<%= render_second_level(second_level_item.id, assigns) %>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
</div>
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Hello all. I have a question as to best practices for code organization when implementing a liveview with a lot of responsibilities.
Sup...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #elixirconf-us
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance











Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sfusato
First option would be to add a LiveView Hook that would re-initialize Bootstrap JS on each
mounted & updateLiveView callback. From Bootstrap docs, it looks like this for V5:Second option, have you considered using Alpine? You can enhance your LiveView templates with Alpine without the need of
phx-update="ignore"and also without the need of hooks manually re-initializing JS libraries due to how it’s set up to work with LiveView (check the end of the section of the previous link).Basically, you will use Alpine instead of Bootstrap JS code to handle the accordion state for you. Something like:
x-datainitializes Alpine; we set open to false;open==true;Sebb
thanks for your help.
Yes I considered Alpine, but I thought for this project I go the easy path.
It turns out, that there is too much magic happening I do not understand.
I think Bootstrap and LiveView is really nice, if you know what you are doing, … but I don’t.
I’ll consider this, but I’m not happy with more Javascript stuff going on I don’t understand.
I think I’ll go the Alpine-and-some-CSS-framework-without-JS-path, it’s a little more work, but at least its possible to understand without being a JS-pro.
cj5
If all you want to do is keep the bootstrap state through LiveView updates without marking the container with
phx-update="ignore", it is possible to use onBeforeElUpdated hook. For example, inside yourapp.jswhere the live socket is initialized: