From d9bdcfcc540699444d76a462cb8963e0185c8ff8 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 9 Mar 2017 21:23:01 -0800 Subject: [PATCH] Deprecate top-level VALID, INVALID, PENDING fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved to AbstractControl class Now Control authors (and others) can access these without importing an implementation library …and we don’t have to add 3 weird consts to one of our libraries --- lib/src/common/forms/model.dart | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/src/common/forms/model.dart b/lib/src/common/forms/model.dart index 3a1f78434..c670662c5 100644 --- a/lib/src/common/forms/model.dart +++ b/lib/src/common/forms/model.dart @@ -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, @@ -41,6 +45,18 @@ Stream _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; @@ -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);