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.
Validate that an association is present
Validates a URL in a changeset field.
Functions
@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"
)
@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
, notcast_assoc
.cast_assoc
provides arequired: true
option. Unlikevalidate_required
, this does not add the field to therequired
list in the schema.
@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
orhttps
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.