Closed gmorell closed 6 months ago
In my experience, you need to set the name
of an input manually when working with array inputs. You can use the index and something like name="#{@name}[#{index}]"
.
I think what would be interesting is to see the rendering phoenix template and generated html). It's probably the names of the inputs that are wrong.
The to_form
implementation of phoenix_ecto
checks the cardinality of a field and sets the name and id to id: name <> "[" <> index_string <> "]"
and id <> "_" <> index_string
respectively.
I think the to_form
implementation of polymorphic_embed needs to check whether the field is of type {:array, PolymorphicEmbed}
and modify the name and id attributes accordingly.
There has been a fix for form input rendering of list of embeds (now we render the index). It probably fixes this issue.
I currently have a schema with this shape:
with the embedded schema as follows:
Given a changeset like so:
I have this rendering via polymorphic_embed_inputs_for/4 the form successfully against the existing data
<%= polymorphic_embed_inputs_for query_form, :queries, :queryquery, fn fp -> %>
, with the array of existing foo/bar fields present. On validation however, I only recieve a single one in the params passed back to the form as so:as opposed to an array like I was expecting
I've been toying around with various solutions but I've reached a bit of an impasse at this time.