ityonemo

ityonemo

Anyone else having trouble with liveview phx-update/append docs?

Is anyone else having trouble with Phoenix Liveview’s phx-update? I feel like I must be doing something dumb or missing something key in the docs (Phoenix.LiveView — Phoenix LiveView v1.2.5).

This code doesn’t do the phx-update/append action, instead it seems to behave like it would if the phx-update term weren’t set.

defmodule LiveMessageTestWeb.TestMessage do
  use Phoenix.LiveView

  def render(assigns) do
    ~L"""
    <div id="chat-messages" phx-update="append">
      <%= for message <- @messages do %>
        <p><%= message %></p>
      <% end %>
    </div>
    """
  end

  def mount(_session, socket) do
    Process.send_after(self(), :ping, 100)
    socket = assign(socket, messages: [])
    {:ok, socket, temporary_assigns: [messages: []]}
  end

  def handle_info(:ping, socket) do
    Process.send_after(self(), :ping, 200)
    new_value = Enum.shuffle(?A..?Z) |> List.to_string
    {:noreply, assign(socket, :messages, [new_value])}
  end
end

First Post!

josevalim

josevalim

Creator of Elixir

I believe your example should work. If you are updating from an old LiveView version, make sure you rebuild your JS.

You can also give the example app a try. It has examples with phx-update: GitHub - chrismccord/phoenix_live_view_example · GitHub

Most Liked

josevalim

josevalim

Creator of Elixir

Nevermind! I have confirmed the bug in your app. thanks for the example :smiley:

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement