Individual Errors for Ecto Array Type in LiveView Form

I have a simple schema with an array of strings: field :examples, {:array, :string} but I have validation errors that I want to display per input, but I don’t see a way to do this with Phoenix.HTML.Form and Ecto.Changeset.

inputs_for only works with embeds and associations, not simple lists, and Ecto.Changeset only seems to be able to add errors for the general field, not elements in the list.

To get around this, I created a form module with embeds_many, but it’s less than ideal, because I have to copy data back and forth between the form struct and the actual model struct.

I ended up changing the type to :map and using embeds_many in the schema. It fixes the duplication issue, but I didn’t like having to change the column just to make it easier to work with the front-end.

Errors are per field in ecto, not per input of which it doesn‘t even know about. You could figure out a metadata scheme to divide up errors between individual array items on your own, but ecto doesn‘t come with that.

Also you can always have a form use a different schema than what you store in the db and map between the representations.