learning123
Hi all!
So, in my component I pass a show_driver_avail_info? prop like so:
prop show_driver_avail_info?, :boolean
And I have this button:
<button type="button" class="rev-Button rev-Button--secondary rev-Button--tiny" phx-click="show_driver_availability_info">See Driver Availability Info</button>
That has this click function:
def handle_event("show_driver_availability_info", _, socket) do
IO.puts("show_driver_availability_info being called")
IO.inspect(socket.assigns.show_driver_avail_info?)
socket = assign(socket, :show_driver_avail_info?, true)
{:noreply, socket}
end
And I have these components, each of which are rendered if show_driver_avail_info is true, and which take in a truck_load and pass it through various other functions to get the info rendered correctly:
<CardInfo :if={{ @show_driver_avail_info? }} label="Time Since Available" title={{ get_time_since_available(@truck_load) }} small />
<CardInfo :if={{ @show_driver_avail_info? }} label="Current Status" title={{ get_driver_current_status(@truck_load) }} small />
<CardInfo :if={{ @show_driver_avail_info? }} label="Time Until Cycle Reset" title={{ get_time_until_cycle_reset(@truck_load) }} small />
I assign the show_driver_avail_info? prop like so in the template file:
<%= live_component @socket, TSSWeb.DispatchHomeLive.Kanban.Column.Component, truck_loads: [], orders: @scheduled, well: @well, show_driver_avail_info?: @show_driver_avail_info? %>
My issue is that whenever I click the button, I can’t see my IO.inspect, and I get this error:
[error] GenServer #PID<0.1218.0> terminating
** (UndefinedFunctionError) function TSSWeb.DispatchHomeLive.handle_event/3 is undefined or private
I am pretty certain I am defining the function in the correct file, so I’m not sure why it’s coming back as undefined or private.
I really appreciate any help!! Thanks
Trending in Questions
Other Trending 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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First 10 of 17 Posts
f0rest8
Going by the error you’re receiving, it could either by a typo in your
handle_event/3function name (name mismatch between your.leexand.exfiles).Another possibility, might be that you are not defining your
handle_event/3function in the correct file. For instance, is it defined in yourindex.exfile or your component file? My initial guess is that it is trying to look in yourindex.exfile or equivalent and is not finding thehandle_event/3function because it has been defined in your component (when the actual click of the button occurs in yourindex.ex).So, I would check where your button click occurs and check that you have defined your
handle_event/3function there and that there aren’t any typos. Typically, the error messages are spot on.sfusato
Try adding the
phx-targetto your button:But, since this looks like a Surface component, you could do this instead:
And Surface will add the target for yourself.
Without a target, events will reach the main liveview, which is what the error message said. See Targeting Component Events in the LiveView docs & Events section in Surface docs.
learning123
hmmm I tried both of these and it’s still giving the same error:
[error] GenServer #PID<0.1218.0> terminating ** (UndefinedFunctionError) function TSSWeb.DispatchHomeLive.handle_event/3 is undefined or privatelearning123
I checked for typos and everything looks right, and the
handle_event/3function is in the file where the button click occurs so I’m not really sure why I’m still getting the[error] GenServer #PID<0.1218.0> terminating ** (UndefinedFunctionError) function TSSWeb.DispatchHomeLive.handle_event/3 is undefined or privateerror…Nicd
Please show your
TSSWeb.DispatchHomeLivemodule code.APB9785
The full error output should also say what arguments were passed to
handle_event/3- can you post that also?learning123
sure thing, here it is:
APB9785
Usually when this issue comes up for me, it’s because of the targeting, like @sfusato was mentioning earlier. I haven’t used Surface, but for a Live Component, adding
phx-target="<%= @myself %>"seems like it should resolve the issue if yourhandle_event/3is in the same file.learning123
This is the error I’m getting after adding that target in
APB9785
Is the name of your component
DispatchHomeLive? You can see in the error message that the app is looking for thehandle_eventthere. So if that’s not the component, then the problem is with the phx-target. My guess is there is something we are not seeing because you are only posting snippets. If you could post a full repo where the issue was happening, it would be easier to troubleshoot.