PhxAdmin v0.9.1 PhxAdmin.ErrorsHelper

The primary purpose of this module is to take nested changeset errors created by many_to_many and has many through relationships and change them into a format that the forms can use to get the error message from the field name.

Changes sets such as: #Ecto.Changeset<action: nil,

changes: %{phone_numbers: [#Ecto.Changeset<action: :update, changes: %{},
   errors: [], data: #ContactDemo.PhoneNumber<>, valid?: true>,
    #Ecto.Changeset<action: :update, changes: %{},
      errors: [number: {"can't be blank", []}], data: #ContactDemo.PhoneNumber<>,
      valid?: false>,
    #Ecto.Changeset<action: :insert, changes: %{label: "Primary Phone"},
      errors: [number: {"can't be blank", []}], data: #ContactDemo.PhoneNumber<>,
      valid?: false>]},
errors: [], data: #ContactDemo.Contact<>, valid?: false>

need to be walked and each of the error messages needs to be flattened into its appropriately namespaced verison.

To do this we need both the changeset and the schema used to generate the changeset. This is required because we need to look at the schema to properly create the neccesary form field names. For example, many_to_many association have attributes appended to the field name so that we know it is a many to many field.

Summary

Functions

create_errors(changeset, schema)