Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions lib/src/common/forms/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import "directives/validators.dart" show ValidatorFn, AsyncValidatorFn;

/// Indicates that a Control is valid, i.e. that no errors exist in the input
/// value.
const VALID = "VALID";
@Deprecated('Use AbstractControl.VALID instead.')
const VALID = AbstractControl.VALID;

/// Indicates that a Control is invalid, i.e. that an error exists in the input
/// value.
const INVALID = "INVALID";
@Deprecated('Use AbstractControl.INVALID instead.')
const INVALID = AbstractControl.INVALID;

/// Indicates that a Control is pending, i.e. that async validation is occurring
/// and errors are not yet available for the input value.
const PENDING = "PENDING";
@Deprecated('Use AbstractControl.VALID instead.')
const PENDING = AbstractControl.PENDING;

bool isControl(Object control) => control is AbstractControl;

AbstractControl _find(AbstractControl control,
Expand All @@ -41,6 +45,18 @@ Stream<dynamic> _toStream(futureOrStream) {
}

abstract class AbstractControl {
/// Indicates that a Control is valid, i.e. that no errors exist in the input
/// value.
static const VALID = "VALID";

/// Indicates that a Control is invalid, i.e. that an error exists in the
/// input value.
static const INVALID = "INVALID";

/// Indicates that a Control is pending, i.e. that async validation is
/// occurring and errors are not yet available for the input value.
static const PENDING = "PENDING";

ValidatorFn validator;
AsyncValidatorFn asyncValidator;
dynamic _value;
Expand All @@ -55,6 +71,9 @@ abstract class AbstractControl {
AbstractControl(this.validator, this.asyncValidator);
dynamic get value => _value;

/// The validation status of the control.
///
/// One of [VALID], [INVALID], or [PENDING].
String get status => _status;

bool get valid => identical(_status, VALID);
Expand Down