View Source KineticEcto.ChangesetValidations (KineticEcto v1.1.1)
Additional validations for use with Ecto.Changeset.
Summary
Functions
Validates that the field or fields provided are not changed once set.
Validates that at least one of the fields
is present (not nil
or blank) in the
changeset
.
Functions
Validates that the field or fields provided are not changed once set.
If the data value (in the incoming struct) is present (not nil
or blank), then any
change which contains an update to that value will be rejected.
Validates that at least one of the fields
is present (not nil
or blank) in the
changeset
.
fields
must be a list of at least two schema field names.
Options
:minimum
: The minimum number of fields that must have a value, default1
. The value provided will be clamped between0
and the number of fields specified.:maximum
: The maximum number of fields that must have a value, defaultnil
. Unspecified by default. If specified, will be clamped between specified, must be at least one and greater than or equal tominimum
and will be clamped to the number of fields specified.:minimum_message
: The message to display when theminimum
threshold of presence is not met.:maximum_message
: The message to display when themaximum
threshold of presence is exceeded.:exact_message
: The message to display whenminimum
andmaximum
are the same exceeded.:message
: The message to be displayed if forwarded tovalidate_required/2
.
There are two special cases:
- If
minimum
is the number of fields passed, this callsvalidate_required/2
. - If
minimum
is0
andmaximum
is unspecified, this validation will always pass.
On validation failure, the minimum_message
or maximum_message
will be added to
each field specified in fields
.
The table below shows the special cases considered.
Minimum | Maximum | Result |
---|---|---|
0 | nil | pass |
#fields | - | Ecto.Changeset.validate_required/3 |
< 0 | - | minimum = 0 |
- | < 1 | maximum = 1 |
> #fields | - | minimum = #fields |
- | > #fields | maximum = #fields |
- | < minimum | maximum = minimum |