I’m taking a liveview class from pragmatic studio and they have the following code:
def render(assigns) do
~L"""
<h1>Front Porch Light</h1>
<div id="light">
<div class="meter">
<span style="width: <%= @brightness %>">
<%= @brightness %>%
</span>
</div>
<button phx-click="off">
<img src="images/light-off.svg" >
</button>
<button phx-click="on">
<img src="images/light-on.svg" >
</button>
</div>
"""
end
def handle_event("on", _, socket) do
socket = assign(socket, :brightness, 100)
{:noreply, socket}
end
def handle_event("off", _, socket) do
socket = assign(socket, :brightness, 0)
{:noreply, socket}
end
the problem is the handle_events
are not being called.
can anybody see what I’m doing wrong,
thanks