The list of errors found for one object, and the way a validator records them.
A Validator receives it in validate and calls rejectValue for a
bad field or reject for a problem of the whole object; the error codes
it passes are turned into full message codes. Code that shows the
errors reads them through fieldErrors, globalErrors and
hasErrors; it usually holds a BindingResult, which adds the target
object.
A nested path lets a validator for a nested object name fields relative
to that object, so one address validator serves billing.city and
shipping.city.
// Reuse an address check inside a larger object.
void validateAddress(Address address, Errors errors) {
errors.pushNestedPath('address');
ValidationUtils.rejectIfEmpty(errors, 'city', 'required');
errors.popNestedPath(); // the error is on 'address.city'
}
Spring (Java):
errors.pushNestedPath("address");
ValidationUtils.rejectIfEmpty(errors, "city", "required");
errors.popNestedPath();
- Implementers
Properties
-
allErrors
→ List<
ObjectError> -
Every error, of fields and of the object, in the order they were
recorded.
no setter
- errorCount → int
-
The number of errors, of fields and of the object.
no setter
- globalError → ObjectError?
-
The first error of the whole object;
nullwhen there is none.no setter -
globalErrors
→ List<
ObjectError> -
The errors of the whole object, the ones that are not FieldErrors,
in the order they were recorded.
no setter
- hasErrors → bool
-
Whether any error, of a field or of the object, was recorded.
no setter
- hasGlobalErrors → bool
-
Whether an error of the whole object (not of a field) was recorded.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- nestedPath ↔ String
-
The path put before the field names given to rejectValue and the
field queries, such as
address.; empty at the top level.getter/setter pair - objectName → String
-
Name of the validated object, such as
signup; part of every message code.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addAllErrors(
Errors errors) → void -
Copies every error of
errors, for example from a validator run on a separate result. Throws an ArgumentError when its objectName differs. -
fieldError(
[String? field]) → FieldError? -
The first error of
field(or of any field when omitted);nullwhen there is none. -
fieldErrors(
[String? field]) → List< FieldError> -
The field errors in the order they were recorded: all when
fieldis omitted, else those offield(relative to nestedPath); a trailing*matches every field under a path (address.*). -
getFieldValue(
String field) → Object? -
The value to show for
fieldin a form: the rejected value of its first error when it has one, else its current value. -
hasFieldErrors(
[String? field]) → bool -
Whether a field has errors: any field when
fieldis omitted, else that field (relative to nestedPath), or every field under a path that ends with*(address.*). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
popNestedPath(
) → void - Goes back to the nested path saved by the last pushNestedPath; throws a StateError when none is saved.
-
pushNestedPath(
String subPath) → void -
Goes one level down: appends
subPath(address,items[0]) to the nested path and saves the current one for popNestedPath. -
reject(
String errorCode, {List< Object?> args, String? defaultMessage, bool renderDefaultMessage}) → void -
Records an error of the whole object with
errorCode, such aspasswordsMismatch. -
rejectValue(
String field, String errorCode, {List< Object?> args, String? defaultMessage, bool renderDefaultMessage}) → void -
Records an error of
field(relative to nestedPath) witherrorCode, such asrequired; the field's current value becomes the rejected value. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited