neurodynamic

neurodynamic

I have a list of html elements generated from a LiveView stream. I want them to show up on the page interspersed with <hr> elements as visual dividers, but this seems to break the stream_delete function. If I display them like this everything works fine

<div id={id} :for={{id, item} <- @streams.items}>
  <%= item.name %>
  <.link
            phx-click={JS.push("delete", value: %{id: item.id}) |> hide("##{item.id}")}
            data-confirm="Are you sure?"
          >Delete</.link>
</div>

but when I try it like this instead

<.intersperse :let={{id, item}} enum={@streams.items}>
  <:separator><hr></:separator>
  <div id={id}>
    <%= item.name %>
    <.link
            phx-click={JS.push("delete", value: %{id: item.id}) |> hide("##{item.id}")}
            data-confirm="Are you sure?"
          >Delete</.link>
  </div>
</.intersperse>

the stream_delete function called when the “Delete” button is pressed doesn’t remove the relevant item from the page (though it does successfully delete it from the database). Anyone know why this breaks it and/or if there’s a way to make it work?

Showing Posts 1 to 5

codeanpeace

codeanpeace

Are you including phx-update="stream" in the parent DOM container?

Required DOM attributes

For stream items to be trackable on the client, the following requirements must be met:

  1. The parent DOM container must include a phx-update="stream" attribute, along with a unique DOM id.
  2. Each stream item must include its DOM id on the item’s element.

source: stream/4 | Phoenix.LiveView docs

Also, what is the intention of hide("##{item.id}"} in phx-click?

neurodynamic

neurodynamic OP

Yup, the phx-update="stream" and ids are all where you’d expect. I’m not sure what the hide("##{item.id}"} is for, but that’s part of the boilerplate for the delete buttons that get autogenerated by mix phx.gen.live.

codeanpeace

codeanpeace

Hmm, the DOM id that LiveView uses to identify streams are set at different level. Are the .intersperse components also setting their id the same way which then clashes with the div level id?

neurodynamic

neurodynamic OP

I don’t think the intersperse component creates any sort of independent wrapper element, so for me, with the parent included it looks like

<div id="items" phx-update="stream">
  <.intersperse :let={{id, item}} enum={@streams.items}>
    <:separator><hr></:separator>
    <div id={id}>
    ...etc...

and the rendered html looks like

<div id="items" phx-update="stream">
  <div id="item-1">
    item name
    [delete link is here]
  </div>
  <hr>
  <div id="item-2">
  ...etc...

I am wondering if maybe using intersperse and with streams might just not be possible, because the separator hr elements don’t have any way to get assigned their own unique ids. They don’t have access to the id variable, so I can’t just give them like "#{id}-separator or something to identify it, and even if I could, my gut would be that the stream implementation probably relies on the assumption that the HTML list created by a stream only has elements directly tied to a specific stream item (trying to find stream rendering in the source code and coming up blank so far).

codeanpeace

codeanpeace

Hmm, that would make sense – have you tried moving the <hr> elements into the <div id="item-x"> elements or alternatively using those divs as wrappers such that the <hr> elements are no longer siblings with them?

Scoping the search to javascript files seems to help.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews