ykostov

ykostov

No function clause matching in handle_event/3

Hello,
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 %>
    <li>
      <strong><%= player.name %></strong>
    </li>

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

WHAT IS MY GOAL: In a schema, where I have player_id from player.id 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)
      timestamps()
    end

For this purpose I need player.id via phx-value-player-id:player.id 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}
  end

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?

Marked As Solved

03juan

03juan

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>

Also Liked

fuelen

fuelen

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

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement