View Source Flamel.Ecto.Validators (flamel v1.10.0)

Some validation functions for Ecto

Summary

Functions

A validate function that checks to see at least one of the fields is not blank

A validate function that requires a field have a value if a condition is met

Functions

Link to this function

validate_at_least_one_required(changeset, fields, msg)

View Source
@spec validate_at_least_one_required(Ecto.Changeset.t(), [atom()], binary()) ::
  Ecto.Changeset.t()

A validate function that checks to see at least one of the fields is not blank

Example

iex> Flamel.Ecto.Validators.validate_at_least_one_required(changeset, [:phone, :email], "either phone or email is required")
Link to this function

validate_required_if(changeset, field, condition, opts)

View Source
@spec validate_required_if(Ecto.Changeset.t(), atom(), function(), keyword()) ::
  Ecto.Changeset.t()

A validate function that requires a field have a value if a condition is met

Example

iex> Flamel.Ecto.Validators.validate_required_if(changeset, :confirm, fn _changeset -> true end) "confirm is required")