Correct usage of phx-value unclear

Hello everyone,

I’ve built a calendar on my own but I have problems to retrieve the value of a clicked span.
My function to render the days inside the calendar looks like this:

<%= for day <- 1..Date.days_in_month(@date) do %>
  <span phx-click="select_day" phx-target="<%= @myself %>" phx-value-day="<% day %>"><%= day %></span>
<% end %>

I define a dynamic value of phx-value but my linter is showing me the following message:

Variable day in code block has no effect as it is never returned (remove the variable or assign it to _ to avoid warnings)

When I hardcode the string like phx-value-day=day the error disappears.

My event handling function is at the moment just a simple print:


def handle_event("select_day", params, socket) do
 IO.inspect(params)

 {:noreply, socket}
end

I’ve searched in the official Phoenix Hexdocs docu but the search results doesn’t show any results for phx-value so I don’t really know where to look for this functionality.

I really appreciate your help!

Edit: Remove unnecessary css classes

You’re missing a = for <% day %>: <%= day %>

2 Likes

Oh my god. What a stupid mistake… Thank you very much and sorry for wasting your time :pensive: