BitcrowdEcto.Changeset (bitcrowd_ecto v0.6.0) View Source
Extensions for Ecto changesets.
Link to this section Summary
Functions
Validates that a field that has been changed.
Validates two date fields to be a date range, so if both are set the first field has to be before the second field. The error is placed on the later field.
Validates a field timestamp to be after the given one
Validates two datetime fields to be a time range, so if both are set the first has to be before the second field. The error is placed on the later field.
Validates that an email has valid format.
Validates a field timestamp to be in the future, if present
Validates that a field is not changed from its current value, unless the current value is nil.
Validates two fields to be a range, so if both are set the first has to be before the second field. The error is placed on the second field.
Validates a field timestamp to be in the past, if present
Validates that a field has changed in a defined way.
Validates a field url to be qualified url
Link to this section Functions
Specs
validate_changed(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
Validates that a field that has been changed.
validate_date_order(changeset, from_field, until_field, opts \\ [])
View Source (since 0.6.0)Specs
validate_date_order(Ecto.Changeset.t(), atom(), atom(), formatter: (... -> any()), valid_orders: [atom()] ) :: Ecto.Changeset.t()
Validates two date fields to be a date range, so if both are set the first field has to be before the second field. The error is placed on the later field.
Examples
validate_date_order(changeset, :from, :to)
validate_date_order(changeset, :from, :to, [valid_orders: :lt])
validate_date_order(changeset, :from, :to, [formatter: &Date.day_of_week/1])
validate_datetime_after(changeset, field, reference_datetime, opts \\ [])
View Source (since 0.6.0)Specs
validate_datetime_after(Ecto.Changeset.t(), atom(), DateTime.t(), [ {:formatter, (... -> any())} ]) :: Ecto.Changeset.t()
Validates a field timestamp to be after the given one
validate_datetime_order(changeset, from_field, until_field, opts \\ [])
View Source (since 0.6.0)Specs
validate_datetime_order(Ecto.Changeset.t(), atom(), atom(), formatter: (... -> any()), valid_orders: [atom()] ) :: Ecto.Changeset.t()
Validates two datetime fields to be a time range, so if both are set the first has to be before the second field. The error is placed on the later field.
Examples
validate_datetime_order(changeset, :from, :to)
validate_datetime_order(changeset, :from, :to, [valid_orders: :lt])
validate_datetime_order(changeset, :from, :to, [formatter: &DateTime.to_time/1])
Specs
validate_email(Ecto.Changeset.t(), atom(), [{:max_length, non_neg_integer()}]) :: Ecto.Changeset.t()
Validates that an email has valid format.
- Ignores nil values.
Compliance
For a good list of valid/invalid emails, see https://gist.github.com/cjaoude/fd9910626629b53c4d25
The regex used in this validator doesn't understand half of the inputs, but we don't really care for now. Validating super strange emails is not a sport we want to compete in.
validate_future_datetime(changeset, field, now \\ DateTime.utc_now())
View Source (since 0.6.0)Specs
validate_future_datetime(Ecto.Changeset.t(), atom(), DateTime.t()) :: Ecto.Changeset.t()
Validates a field timestamp to be in the future, if present
Specs
validate_immutable(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
Validates that a field is not changed from its current value, unless the current value is nil.
validate_order(changeset, from_field, until_field, validation_key, opts \\ [])
View Source (since 0.6.0)Specs
validate_order(Ecto.Changeset.t(), atom(), atom(), atom(), formatter: (... -> any()), compare_fun: (... -> any()), valid_orders: [atom()] ) :: Ecto.Changeset.t()
Validates two fields to be a range, so if both are set the first has to be before the second field. The error is placed on the second field.
Examples
validate_order(changeset, :from, :to, :to_is_after_from)
validate_order(changeset, :from, :to, :to_is_after_from, [compare_fun: fn a, b -> String.length(a) > String.length(b) end])
validate_order(changeset, :from, :to, :to_is_after_from, [formatter: &String.length/1])
validate_past_datetime(changeset, field, now \\ DateTime.utc_now())
View Source (since 0.6.0)Specs
validate_past_datetime(Ecto.Changeset.t(), atom(), DateTime.t()) :: Ecto.Changeset.t()
Validates a field timestamp to be in the past, if present
Specs
validate_transition(Ecto.Changeset.t(), atom(), [{any(), any()}]) :: Ecto.Changeset.t()
Validates that a field has changed in a defined way.
Examples
validate_transition(changeset, field, [{"foo", "bar"}, {"foo", "yolo"}])
This marks the changeset invalid unless the value of :field
is currently "foo"
and is
changed to "bar"
or "yolo"
. If the field is not changed, a {state, state}
transition
has to be present in the list of transitions.
Specs
validate_url(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
Validates a field url to be qualified url