FieldError class

A validation or binding error about one field of an object: which field, the value that was rejected, and the message codes.

There are two kinds. A binding failure (bindingFailure is true) means the input could not be stored at all, such as 'old' for an int; its code is typeMismatch and rejectedValue is the raw input. A validation error means the value was stored but breaks a rule, such as @Min(18); its code is the constraint's name.

Applications read field errors to show them next to form fields or to shape an error response; they get them from BindingResult.fieldErrors. The web starter already writes each one into a 400 as field, message and rejectedValue.

// After binding `{'age': 'old'}` onto a form with an int age.
final error = binder.bindingResult.fieldError('age')!;
error.field; // 'age'
error.rejectedValue; // 'old'
error.bindingFailure; // true: 'old' is not an int

Spring (Java):

FieldError error = binder.getBindingResult().getFieldError("age");
error.getField();
error.getRejectedValue();
error.isBindingFailure();
Inheritance

Constructors

FieldError(String objectName, String field, Object? rejectedValue, List<String> codes, {List<Object?> arguments = const [], String? defaultMessage, bool shouldRenderDefaultMessage = true, bool bindingFailure = false})
An error of field of the object objectName that rejected rejectedValue; bindingFailure marks a value that could not be converted.

Properties

arguments → List<Object?>
The values for the {0}, {1}, ... placeholders; an argument that is itself a MessageSourceResolvable is translated first.
finalinherited
bindingFailure → bool
Whether the input could not be stored in the field (for example text for a number) rather than breaking a constraint. A field with a binding failure gets no constraint errors on top.
final
code → String
The plain error code, the last and least specific of codes: NotBlank for [NotBlank.signup.name, NotBlank.name, NotBlank.String, NotBlank]. For a failed constraint it is the constraint's name.
no setterinherited
codes → List<String>
The codes tried in order; the last is the most general.
finalinherited
defaultMessage → String?
The text used when no code is found; null makes a missing message an error.
finalinherited
field → String
Full property path of the field, such as name, address.city or items[0].sku.
final
hashCode → int
The hash code for this object.
no setterinherited
objectName → String
Name of the validated object, such as signup; part of the message codes. The web starter uses the name of the validated parameter.
finalinherited
rejectedValue → Object?
The value that was rejected: the raw input for a binding failure, the invalid value for a validation error. Show it to let the user fix what they typed.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
shouldRenderDefaultMessage → bool
Whether a message source formats defaultMessage with arguments ({0}, {1}) before showing it; true by default.
finalinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited