View Source Lightning.Validators (Lightning v2.10.4)

Extra validators for Ecto.Changeset.

Summary

Functions

Validate that only one of the fields is set at a time.

Validate that at least one of the fields is set.

Validates a URL in a changeset field.

Functions

Link to this function

validate_exclusive(changeset, fields, message)

View Source
@spec validate_exclusive(Ecto.Changeset.t(), [atom()], String.t()) ::
  Ecto.Changeset.t()

Validate that only one of the fields is set at a time.

Example:

changeset
|> validate_exclusive(
  [:source_job_id, :source_trigger_id],
  "source_job_id and source_trigger_id are mutually exclusive"
)
Link to this function

validate_one_required(changeset, fields, message)

View Source
@spec validate_one_required(Ecto.Changeset.t(), [atom()], String.t()) ::
  Ecto.Changeset.t()

Validate that at least one of the fields is set.

Link to this function

validate_required_assoc(changeset, assoc, message \\ "is required")

View Source
@spec validate_required_assoc(Ecto.Changeset.t(), atom(), String.t()) ::
  Ecto.Changeset.t()

Validate that an association is present

NOTE This should only be used when using put_assoc, not cast_assoc. cast_assoc provides a required: true option. Unlike validate_required, this does not add the field to the required list in the schema.

Link to this function

validate_url(changeset, field)

View Source
@spec validate_url(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()

Validates a URL in a changeset field.

Ensures that the URL:

  • Has a valid http or https scheme.
  • Has a valid host (domain name, IPv4, or IPv6).
  • The host is not blank and does not exceed 255 characters.

Returns a changeset error for invalid URLs.