Display Changeset Errors

Learn how to display changeset errors.

Our form is working well, but something is missing. If the user submits invalid data, the call to Repo.insert will fail. We currently have no way of showing the user how to fix the problem, though. The changeset contains the validation errors, so we need to add some elements to the page to display them. Let’s do that now.

Add helper functions

We’ll start by adding a new helper function, error_tag/2. This function is not provided by default, so we need to define it ourselves. We can add it to any module we’re using for storing helper functions.

Get hands-on with 1200+ tech skills courses.