class Marten::Core::Validation::ErrorSet
- Marten::Core::Validation::ErrorSet
- Reference
- Object
Overview
Represents a set of validation errors.
Included Modules
Defined in:
marten/core/validation/error_set.crmarten/template/ext/core/validation/error_set.cr
Constant Summary
-
DEFAULT_ERROR_TYPE =
:invalid
Constructors
Instance Method Summary
-
#[](field : Nil | String | Symbol)
Returns all the errors associated with a specific field.
-
#add(field : String | Symbol, message : String, *, type : Nil | String | Symbol = nil)
Adds a new field error to the error set.
-
#add(message : String, *, type : Nil | String | Symbol = nil)
Adds a new global error to the error set.
-
#clear(*args, **options)
Clears all the
Marten::Core::Validation::Error
objects from this error set. -
#clear(*args, **options, &)
Clears all the
Marten::Core::Validation::Error
objects from this error set. -
#each(*args, **options)
Iterates over all the
Marten::Core::Validation::Error
objects in this error set. -
#each(*args, **options, &)
Iterates over all the
Marten::Core::Validation::Error
objects in this error set. -
#global
Returns the global errors (errors that are not associated with a specific field).
-
#size(*args, **options)
Returns the number of errors.
-
#size(*args, **options, &)
Returns the number of errors.
Constructor Detail
Instance Method Detail
Adds a new field error to the error set.
This method can be used to add a new error associated with a specific field to an existing error set. At least
a field
and a message
must be specified:
record.errors.add(:attribute, "This record attribute is invalid")
Optionnaly, an error type
can be explicitely specified, otherwise it defaults to :invalid
:
records.errors.add(:attribute, "This record attribute is invalid!", type: :invalid_attribute)
Adds a new global error to the error set.
This method can be used to add a new global error (that is not associated with a specific field) to an
existing error set. At least a message
must be specified:
record.errors.add("This record is invalid!")
Optionnaly, an error type
can be explicitely specified, otherwise it defaults to :invalid
:
record.errors.add("This record is invalid!", type: :invalid_record)
Clears all the Marten::Core::Validation::Error
objects from this error set.
Clears all the Marten::Core::Validation::Error
objects from this error set.
Iterates over all the Marten::Core::Validation::Error
objects in this error set.
Iterates over all the Marten::Core::Validation::Error
objects in this error set.