LiveView events not working on a form

I have a table where each row can be updated with an inline form, the form is rendered when the page is (not after a user hits an “edit” button) so the editing experience is semeless.

I’m doing this by creating changesets for every item on the table and then looping through the changesets:

  socket
    |> assign(:changesets, changesets_for_items)
    |> ok()

Then in the index.html.leex
I have something like this:

<%= for change <- @changesets do %>
              <tr>
                <%= f = form_for change, "#",
                        phx_submit: "save_form",
                        phx_change: "toggl_forme",
                        phx_value_toggled: change.data.id,
                        id: change.data.id
                         %>

None of these events are working. I’ve noticed things seem to work if, rather than creating multiple changesets I just create one and have the form outside of the loop (at this point this is feasible since there is only one record but in the future, there could be up a dozen or so).

I’m wondering if this expected because I am doing something wrong or if the above snippets should work.

Turns out you can not place a form inside a table row… period. I will spend the afternoon rebuilding this table with divs!

3 Likes