How to manipulate `embeds_many` for `inputs_for` with LiveView


I’ve successfully followed this tutorial (with slight modifications) to add and remove embeds_many form fields in inputs_for with LiveView.

Now I’d like to preprocess the embedded records so that they’re sorted by a custom function and the fields marked to be deleted are hidden (I also want to replace the “delete” checkbox with a button). The problem is that I don’t know how I can manipulate the form and pass the result to inputs_for.

As for hiding to-be-deleted items, I’ve already tried several things like the following but nothing works (apparently because LiveView doesn’t see the updated values):

<%= f = form_for ... %>
    <%= for item <- inputs_for(f, :items) do %>
        <%= if not Map.has_key?(item, :changes) || is_nil(item.changes.delete) do %>
        <% end %>
    <% end %>

Thanks in advance!