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
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
Your implementation of handle_event/2 expects "player-id" key to be present, but it is absent
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









