feat(forms): add invalid prop to abstract controls (#10439)
This commit is contained in:
parent
3e377f520e
commit
e0eea6c2f4
|
@ -27,6 +27,10 @@ export abstract class AbstractControlDirective {
|
||||||
|
|
||||||
get valid(): boolean { return isPresent(this.control) ? this.control.valid : null; }
|
get valid(): boolean { return isPresent(this.control) ? this.control.valid : null; }
|
||||||
|
|
||||||
|
get invalid(): boolean { return isPresent(this.control) ? this.control.invalid : null; }
|
||||||
|
|
||||||
|
get pending(): boolean { return isPresent(this.control) ? this.control.pending : null; }
|
||||||
|
|
||||||
get errors(): {[key: string]: any} {
|
get errors(): {[key: string]: any} {
|
||||||
return isPresent(this.control) ? this.control.errors : null;
|
return isPresent(this.control) ? this.control.errors : null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,6 @@ export abstract class AbstractControl {
|
||||||
private _parent: FormGroup|FormArray;
|
private _parent: FormGroup|FormArray;
|
||||||
private _asyncValidationSubscription: any;
|
private _asyncValidationSubscription: any;
|
||||||
|
|
||||||
|
|
||||||
constructor(public validator: ValidatorFn, public asyncValidator: AsyncValidatorFn) {}
|
constructor(public validator: ValidatorFn, public asyncValidator: AsyncValidatorFn) {}
|
||||||
|
|
||||||
get value(): any { return this._value; }
|
get value(): any { return this._value; }
|
||||||
|
@ -92,6 +91,8 @@ export abstract class AbstractControl {
|
||||||
|
|
||||||
get valid(): boolean { return this._status === VALID; }
|
get valid(): boolean { return this._status === VALID; }
|
||||||
|
|
||||||
|
get invalid(): boolean { return this._status === INVALID; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the errors of this control.
|
* Returns the errors of this control.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -151,6 +151,8 @@ export function main() {
|
||||||
expect(form.control).toBe(formModel);
|
expect(form.control).toBe(formModel);
|
||||||
expect(form.value).toBe(formModel.value);
|
expect(form.value).toBe(formModel.value);
|
||||||
expect(form.valid).toBe(formModel.valid);
|
expect(form.valid).toBe(formModel.valid);
|
||||||
|
expect(form.invalid).toBe(formModel.invalid);
|
||||||
|
expect(form.pending).toBe(formModel.pending);
|
||||||
expect(form.errors).toBe(formModel.errors);
|
expect(form.errors).toBe(formModel.errors);
|
||||||
expect(form.pristine).toBe(formModel.pristine);
|
expect(form.pristine).toBe(formModel.pristine);
|
||||||
expect(form.dirty).toBe(formModel.dirty);
|
expect(form.dirty).toBe(formModel.dirty);
|
||||||
|
@ -318,6 +320,8 @@ export function main() {
|
||||||
expect(form.control).toBe(formModel);
|
expect(form.control).toBe(formModel);
|
||||||
expect(form.value).toBe(formModel.value);
|
expect(form.value).toBe(formModel.value);
|
||||||
expect(form.valid).toBe(formModel.valid);
|
expect(form.valid).toBe(formModel.valid);
|
||||||
|
expect(form.invalid).toBe(formModel.invalid);
|
||||||
|
expect(form.pending).toBe(formModel.pending);
|
||||||
expect(form.errors).toBe(formModel.errors);
|
expect(form.errors).toBe(formModel.errors);
|
||||||
expect(form.pristine).toBe(formModel.pristine);
|
expect(form.pristine).toBe(formModel.pristine);
|
||||||
expect(form.dirty).toBe(formModel.dirty);
|
expect(form.dirty).toBe(formModel.dirty);
|
||||||
|
@ -392,6 +396,8 @@ export function main() {
|
||||||
expect(controlGroupDir.control).toBe(formModel);
|
expect(controlGroupDir.control).toBe(formModel);
|
||||||
expect(controlGroupDir.value).toBe(formModel.value);
|
expect(controlGroupDir.value).toBe(formModel.value);
|
||||||
expect(controlGroupDir.valid).toBe(formModel.valid);
|
expect(controlGroupDir.valid).toBe(formModel.valid);
|
||||||
|
expect(controlGroupDir.invalid).toBe(formModel.invalid);
|
||||||
|
expect(controlGroupDir.pending).toBe(formModel.pending);
|
||||||
expect(controlGroupDir.errors).toBe(formModel.errors);
|
expect(controlGroupDir.errors).toBe(formModel.errors);
|
||||||
expect(controlGroupDir.pristine).toBe(formModel.pristine);
|
expect(controlGroupDir.pristine).toBe(formModel.pristine);
|
||||||
expect(controlGroupDir.dirty).toBe(formModel.dirty);
|
expect(controlGroupDir.dirty).toBe(formModel.dirty);
|
||||||
|
@ -418,6 +424,8 @@ export function main() {
|
||||||
expect(formArrayDir.control).toBe(formModel);
|
expect(formArrayDir.control).toBe(formModel);
|
||||||
expect(formArrayDir.value).toBe(formModel.value);
|
expect(formArrayDir.value).toBe(formModel.value);
|
||||||
expect(formArrayDir.valid).toBe(formModel.valid);
|
expect(formArrayDir.valid).toBe(formModel.valid);
|
||||||
|
expect(formArrayDir.invalid).toBe(formModel.invalid);
|
||||||
|
expect(formArrayDir.pending).toBe(formModel.pending);
|
||||||
expect(formArrayDir.errors).toBe(formModel.errors);
|
expect(formArrayDir.errors).toBe(formModel.errors);
|
||||||
expect(formArrayDir.pristine).toBe(formModel.pristine);
|
expect(formArrayDir.pristine).toBe(formModel.pristine);
|
||||||
expect(formArrayDir.dirty).toBe(formModel.dirty);
|
expect(formArrayDir.dirty).toBe(formModel.dirty);
|
||||||
|
@ -433,6 +441,8 @@ export function main() {
|
||||||
expect(controlDir.control).toBe(control);
|
expect(controlDir.control).toBe(control);
|
||||||
expect(controlDir.value).toBe(control.value);
|
expect(controlDir.value).toBe(control.value);
|
||||||
expect(controlDir.valid).toBe(control.valid);
|
expect(controlDir.valid).toBe(control.valid);
|
||||||
|
expect(controlDir.invalid).toBe(control.invalid);
|
||||||
|
expect(controlDir.pending).toBe(control.pending);
|
||||||
expect(controlDir.errors).toBe(control.errors);
|
expect(controlDir.errors).toBe(control.errors);
|
||||||
expect(controlDir.pristine).toBe(control.pristine);
|
expect(controlDir.pristine).toBe(control.pristine);
|
||||||
expect(controlDir.dirty).toBe(control.dirty);
|
expect(controlDir.dirty).toBe(control.dirty);
|
||||||
|
@ -484,6 +494,8 @@ export function main() {
|
||||||
expect(ngModel.control).toBe(control);
|
expect(ngModel.control).toBe(control);
|
||||||
expect(ngModel.value).toBe(control.value);
|
expect(ngModel.value).toBe(control.value);
|
||||||
expect(ngModel.valid).toBe(control.valid);
|
expect(ngModel.valid).toBe(control.valid);
|
||||||
|
expect(ngModel.invalid).toBe(control.invalid);
|
||||||
|
expect(ngModel.pending).toBe(control.pending);
|
||||||
expect(ngModel.errors).toBe(control.errors);
|
expect(ngModel.errors).toBe(control.errors);
|
||||||
expect(ngModel.pristine).toBe(control.pristine);
|
expect(ngModel.pristine).toBe(control.pristine);
|
||||||
expect(ngModel.dirty).toBe(control.dirty);
|
expect(ngModel.dirty).toBe(control.dirty);
|
||||||
|
@ -540,6 +552,8 @@ export function main() {
|
||||||
expect(controlNameDir.control).toBe(formModel);
|
expect(controlNameDir.control).toBe(formModel);
|
||||||
expect(controlNameDir.value).toBe(formModel.value);
|
expect(controlNameDir.value).toBe(formModel.value);
|
||||||
expect(controlNameDir.valid).toBe(formModel.valid);
|
expect(controlNameDir.valid).toBe(formModel.valid);
|
||||||
|
expect(controlNameDir.invalid).toBe(formModel.invalid);
|
||||||
|
expect(controlNameDir.pending).toBe(formModel.pending);
|
||||||
expect(controlNameDir.errors).toBe(formModel.errors);
|
expect(controlNameDir.errors).toBe(formModel.errors);
|
||||||
expect(controlNameDir.pristine).toBe(formModel.pristine);
|
expect(controlNameDir.pristine).toBe(formModel.pristine);
|
||||||
expect(controlNameDir.dirty).toBe(formModel.dirty);
|
expect(controlNameDir.dirty).toBe(formModel.dirty);
|
||||||
|
|
|
@ -5,6 +5,7 @@ export declare abstract class AbstractControl {
|
||||||
errors: {
|
errors: {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
invalid: boolean;
|
||||||
pending: boolean;
|
pending: boolean;
|
||||||
pristine: boolean;
|
pristine: boolean;
|
||||||
root: AbstractControl;
|
root: AbstractControl;
|
||||||
|
@ -61,7 +62,9 @@ export declare abstract class AbstractControlDirective {
|
||||||
errors: {
|
errors: {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
invalid: boolean;
|
||||||
path: string[];
|
path: string[];
|
||||||
|
pending: boolean;
|
||||||
pristine: boolean;
|
pristine: boolean;
|
||||||
statusChanges: Observable<any>;
|
statusChanges: Observable<any>;
|
||||||
touched: boolean;
|
touched: boolean;
|
||||||
|
|
Loading…
Reference in New Issue