Kronky v0.5.0 Kronky.ChangesetParser View Source
Converts an ecto changeset into a list of validation errors structs. Currently does not support nested errors
Link to this section Summary
Functions
Generate a single Kronky.ValidationMessage struct from a changeset
Generate a list of Kronky.ValidationMessage structs from changeset errors
Inserts message variables into message
Extract a nested map of raw errors from a changeset
Generate unique code for each validation type
Link to this section Functions
Generate a single Kronky.ValidationMessage struct from a changeset.
This method is designed to be used with Ecto.Changeset.traverse_errors to generate a map of structs.
## Examples
```
error_map = Changeset.traverse_errors(fn(changeset, field, error) ->
Kronky.ChangesetParser.construct_message(field, error)
end)
error_list = Enum.flat_map(error_map, fn({_, messages}) -> messages end)
```
Generate a list of Kronky.ValidationMessage structs from changeset errors
For examples, please see the test cases in the github repo.
Inserts message variables into message.
Examples
iex> interpolate_message({"length should be between %{one} and %{two}", [one: "1", two: "2", three: "3"]})
"length should be between 1 and 2"
Extract a nested map of raw errors from a changeset
For examples, please see the test cases in the github repo.
Generate unique code for each validation type.
Expects an array of validation options such as those supplied
by Ecto.Changeset.traverse_errors/2, with the addition of a message key containing the message string.
Messages are required for several validation types to be identified.
Supported
- :cast - generated by
Ecto.Changeset.cast/3 - :association - generated by
Ecto.Changeset.assoc_constraint/3,Ecto.Changeset.cast_assoc/3,Ecto.Changeset.put_assoc/3,Ecto.Changeset.cast_embed/3,Ecto.Changeset.put_embed/3 - :acceptance - generated by
Ecto.Changeset.validate_acceptance/3 - :confirmation - generated by
Ecto.Changeset.validate_confirmation/3 - :length - generated by
Ecto.Changeset.validate_length/3when the:isoption fails validation - :min - generated by
Ecto.Changeset.validate_length/3when the:minoption fails validation - :max - generated by
Ecto.Changeset.validate_length/3when the:maxoption fails validation - :less_than_or_equal_to - generated by
Ecto.Changeset.validate_length/3when the:less_than_or_equal_tooption fails validation - :less_than - generated by
Ecto.Changeset.validate_length/3when the:less_thanoption fails validation - :greater_than_or_equal_to - generated by
Ecto.Changeset.validate_length/3when the:greater_than_or_equal_tooption fails validation - :greater_than - generated by
Ecto.Changeset.validate_length/3when the:greater_thanoption fails validation - :equal_to - generated by
Ecto.Changeset.validate_length/3when the:equal_tooption fails validation - :exclusion - generated by
Ecto.Changeset.validate_exclusion/4 - :inclusion - generated by
Ecto.Changeset.validate_inclusion/4 - :required - generated by
Ecto.Changeset.validate_required/3 - :subset - generated by
Ecto.Changeset.validate_subset/4 - :unique - generated by
Ecto.Changeset.unique_constraint/3 - :foreign - generated by
Ecto.Changeset.foreign_key_constraint/3 - :no_assoc_constraint - generated by
Ecto.Changeset.no_assoc_constraint/3 - :unknown - supplied when validation cannot be matched. This will also match any custom errors added through
Ecto.Changeset.add_error/4,Ecto.Changeset.validate_change/3, andEcto.Changeset.validate_change/4