I can’t seem to find anything that matches my use case, which seems kind of crazy. Maybe I’m just looking in the wrong place. I have an address form that is connected with an api that tells me if the address is real or not. If it isn’t real it sends back errors based on validation etc etc. These get returned in {:error, changeset}.
My issue is putting all of these errors on the screen at the same time, right now I can only seem to do it one at a time.
This is what I’m doing right now, where the redirect goes back to the page they were on when trying to submit the form. Of course, this doesn’t work when there are multiple errors. Is there anyway around this?
Interesting, that looks like it could work. Does this mean I can’t put multiple errors (or flashes) on the screen at the same time without writing code on the client side as well?
So the issue seems to be that I can’t access the mapping of the errors(or don’t know how).
For example, my changeset errors come in the form
[ geocoding: {“our application blah blah” , []} ]
but when I call traverse_errors/2 and inspect the message it’s just “our application blah blah”, which is all I want in the first place. Is there a way to strip the errors that doesn’t include pattern matching since we don’t know if the errors will always be formatted this way?
Then you can build the flash message by going over the map:
# you can also use iolists to build the message
traversed_errors_map
|> Enum.map(fn {key, errors} ->
"#{key}: #{Enum.join(errors, ", ")}"
end)
|> Enum.join("\n")