Displaying Ecto Embedded Schema changeset Erros on Phoenix form

Just came across this issue where with nested associations Ecto actually nests changesets within each other, storing them against the association name. Calling the errors key on the struct is only going to give us the errors on the primary changeset, or in our case the User and not traverse the nested changeset for the Address.

%Ecto.Changeset{action: nil,
 changes: %{address: %Ecto.Changeset{action: :insert,
 changes: %{address1: “123 Main St”, city: “New York”}, constraints:[],
 errors: [country: “can’t be blank”], filters: %{},
 model: %UserAddress.Address{}}

Because of this Phoenix fails to show the errors on the forms properly with error_tags.

Is the only solution to this is traverse_errors/2 ?

1 Like

Normally this works as expected when using inputs_for to build the fields for the embedded association; can you show how you’re using error_tag?

1 Like

This is the error tag I use, just a note, this is an embedded schema inside another embedded schema. In the second nested level, i use a inputs_for but all the fields are hidden and this :field is the parent attribute of the second nested level embedded schema

<%= error_tag(f, :field, class: error_tag_class) %>