I have used the phx.gen.live generator to build a simple form containing an string array.
Then I’m editing it using:
<.form
let={f}
for={@changeset}
id="post-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save">
<%= label f, :parts %>
<%= for part <- @post.parts do %>
<input name="post[parts][]" value={part} />
<% end %>
</.form>
it works and correctly saves the changes to DB.
nonetheless, if I edit one input, the others reset to their original value.
So I started digging and checking what the changeset coming to the backend contains, checked no validation error was being generated and finally I concluded this: changing be content of the inputs triggers the “validate” event and it forces a redraw of the form, wiping out the modifications done until then
Weirdly enough the liveview diff coming for rerendering over websocket is huge, maybe it’s not possible to use “for” in the forms of liveview because it breaks the diffing engine?