Skip to content
Closed
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions modules/angular2/src/core/forms/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const VALID = "VALID";
*/
export const INVALID = "INVALID";

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

export function isControl(control: Object): boolean {
return control instanceof AbstractControl;
}
Expand Down Expand Up @@ -75,6 +81,7 @@ export class AbstractControl {
get untouched(): boolean { return !this._touched; }

get valueChanges(): Observable { return this._valueChanges; }
get pending(): boolean { return this._status == PENDING; }

markAsTouched(): void { this._touched = true; }

Expand All @@ -87,6 +94,15 @@ export class AbstractControl {
}
}

markAsPending({onlySelf}: {onlySelf?: boolean} = {}): void {
onlySelf = normalizeBool(onlySelf);
this._status = PENDING;

if (isPresent(this._parent) && !onlySelf) {
this._parent.markAsPending({onlySelf: onlySelf});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same as this._parent.markAsPending() ?

}
}

setParent(parent: ControlGroup | ControlArray): void { this._parent = parent; }

updateValidity({onlySelf}: {onlySelf?: boolean} = {}): void {
Expand Down
18 changes: 18 additions & 0 deletions modules/angular2/test/core/forms/model_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,24 @@ export function main() {
});
});

describe("pending", () => {
var c: Control;
var a: ControlArray;

beforeEach(() => {
c = new Control('value');
a = new ControlArray([c]);
});

it("should be false after creating a control", () => { expect(a.pending).toEqual(false); });

it("should be false after changing the value of the control", () => {
c.markAsPending();

expect(a.pending).toEqual(true);
});
});

describe("valueChanges", () => {
var a: ControlArray;
var c1, c2;
Expand Down
8 changes: 8 additions & 0 deletions modules/angular2/test/public_api_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ var NG_API = [
'AbstractControl.getError()',
'AbstractControl.hasError()',
'AbstractControl.markAsDirty()',
'AbstractControl.markAsPending()',
'AbstractControl.markAsTouched()',
'AbstractControl.pending',
'AbstractControl.pristine',
'AbstractControl.setParent()',
'AbstractControl.status',
Expand Down Expand Up @@ -277,7 +279,9 @@ var NG_API = [
'Control.getError()',
'Control.hasError()',
'Control.markAsDirty()',
'Control.markAsPending()',
'Control.markAsTouched()',
'Control.pending',
'Control.pristine',
'Control.registerOnChange()',
'Control.setParent()',
Expand All @@ -304,7 +308,9 @@ var NG_API = [
'ControlArray.insert()',
'ControlArray.length',
'ControlArray.markAsDirty()',
'ControlArray.markAsPending()',
'ControlArray.markAsTouched()',
'ControlArray.pending',
'ControlArray.pristine',
'ControlArray.push()',
'ControlArray.removeAt()',
Expand Down Expand Up @@ -345,7 +351,9 @@ var NG_API = [
'ControlGroup.hasError()',
'ControlGroup.include()',
'ControlGroup.markAsDirty()',
'ControlGroup.markAsPending()',
'ControlGroup.markAsTouched()',
'ControlGroup.pending',
'ControlGroup.pristine',
'ControlGroup.removeControl()',
'ControlGroup.setParent()',
Expand Down