Phx-value not passed to handle_event

Hi all,
when using the Phoenix.HTML.Link.link/2 function in a leex template only an empty struct gets passed to the handle_event function.

<%= link to: "#", "phx-click": "delete_session", "phx-value": session.id, title: "Delete" do %> <i class="fa fa-trash"></i> <% end %>

Generated HTML seems also fine:

<a  href="#" phx-click="delete_session" phx-value="3" title="Delete"> <i class="fa fa-trash"></i> </a>

I also tried it with phx_click and phx_value. Oddly, my event gets triggered, but fails due to the missing parameter.

  def handle_event("delete_session", id, socket) do
    session = MyApp.get_session!(id)
    {:ok, _session} = MyApp.delete_session(session)

    {:noreply, fetch(socket)}
  end

In the console it shows that only %{} gets transmitted to the function.
I use a button at different parts of the project and there the values get transmitted, but this also does not work here … Feeling stuck

Try phx-value-id rather than phx-value and see what you get…

2 Likes

Just adding to what @mindok already suggested, also pattern match id out of 2nd function argument: %{"id" => id}

Thanks for the fast response. Changing it to phx-value-id solved the issue.