Hi, I am starting to learn LiveView and trying to make phx-click work. Here’s what I want to do: when user clicks on a table row, redirect to a page that shows details of that row.
I have added a phx-click
to my row in index.html.heex:
<tr id={"customer-#{customer.id}"} phx-click="show">
I have added a dummy handler in index.ex:
@impl true
def handle_event("show", %{"id" => id}, socket) do
IO.puts("Customer clicked")
{:noreply, socket}
end
- When I click the handler, I get this error in the console. Looks like LiveView is not finding my handler:
[error] GenServer #PID<0.2738.0> terminating
** (FunctionClauseError) no function clause matching in DemotwWeb.CustomerLive.Index.handle_event/3
(demotw 0.1.0) lib/demotw_web/live/customer_live/index.ex:38: DemotwWeb.CustomerLive.Index.handle_event("show", %{}, #Phoenix.LiveView.Socket<assigns: %{__changed__: %{}, customer: nil, customers: [], flash: %{}, live_action: :index, page_title: "Listing Customers"}, endpoint: DemotwWeb.Endpoint, id: "phx-FuGGIKtRbaQdjB7h", parent_pid: nil, root_pid: #PID<0.2738.0>, router: DemotwWeb.Router, transport_pid: #PID<0.2730.0>, view: DemotwWeb.CustomerLive.Index, ...>)
- When I get past the above issue, how do I redirect to the show page?
Any help would be greatly appreciated.