No function clause matching in handle_event/3

I can’t understand why I get this error: no function clause matching in TennisPhxWeb.TourLive.handle_event/3 (tennis_phx 0.1.0) lib/tennis_phx_web/live/tour_live.ex:31: TennisPhxWeb.TourLive.handle_event("add_points", %{"player_points" => %{"points" => "2"}},.

My heex template:

  <%= for player <- @players do %>
      <strong><%= %></strong>

    <form action="#" phx-submit="add_points" phx-value-player-id: "">
      <%= number_input :player_points, :points, placeholder: "Something" %>
      <%= submit "Add", phx_disable_with: "Adding...." %>
  <% end %>

WHAT IS MY GOAL: In a schema, where I have player_id from I want to record some points.

  def change do
    create table(:player_tour) do
      add(:player_id, references(:players, on_delete: :delete_all))
      add(:tour_id, references(:tours, on_delete: :delete_all))
      add(:points, :decimal)

For this purpose I need via in my form. The handle event, where the error is all about:

  def handle_event("add_points", %{"player_points" => points_for_player, "player-id" => player_id}, socket) do
    tour = socket.assigns[:tour]
           |> Repo.preload(:players)
    Events.bump_player_points(tour, player_id, points_for_player)
    {:noreply, socket}

No function clause matching in handle_event/3… I think the error is that I use 4 arguments, although player_points and player-id are both unsigned params - here. From this I understand that my cause can be done, can’t it?

Any thoughts?

Your implementation of handle_event/2 expects "player-id" key to be present, but it is absent

1 Like

You used a : instead of = for your HTML attribute.

Interestingly, check out what chromium does when trying to parse semantically-incorrect markup:
<div id="test" data-test1="1" data-test2: "2"></div> becomes <div id="test" data-test1="1" data-test2:="" "2"=""></div>

1 Like