I’m rendering a form that has multiple associations with multiple corresponding inputs_for
. There’s no issue trying to group the like associations together, however if I need to group them in a specific order, for example in the form:
-sub entity 1
-sub entity 2
-sub entity 1
I’m hoping to get some ideas on ways to handle this.
Here’s a bit about the dummy project:
I have my Entity
and two associated sub-entities:
defmodule MyApp.Entity do
...
schema "entities" do
has_many :sub_entity_1, SubEntity1
has_many :sub_entity_2, SubEntity2
end
...
end
And then my form:
<%= form_for @entity_changeset, Routes.entity_path(@conn, :create), fn f -> %>
<%= inputs_for f, :sub_entity_1, fn fi -> %>
<%= textarea fi, :value %>
<% end %>
<%= inputs_for f, :sub_entity_2, fn fi -> %>
<%= textarea fi, :value %>
<% end %>
<% end %>
Is there way to maybe specify the that I want to not group all the sub_entity_1
and sub_entity_2
together? I looked through the docs for inputs_for
, and it says that it can be used to work with single entities, but couldn’t find anything more on how that would work for my case (https://github.com/phoenixframework/phoenix_html/blob/v2.13.2/lib/phoenix_html/form.ex#L165).