diff --git a/modules/@angular/common/src/forms/directives/ng_form.ts b/modules/@angular/common/src/forms/directives/ng_form.ts index 704d9178b1..8109f88a20 100644 --- a/modules/@angular/common/src/forms/directives/ng_form.ts +++ b/modules/@angular/common/src/forms/directives/ng_form.ts @@ -86,6 +86,8 @@ export const formDirectiveProvider: any = exportAs: 'ngForm' }) export class NgForm extends ControlContainer implements Form { + private _submitted: boolean = false; + form: ControlGroup; ngSubmit = new EventEmitter(); @@ -96,6 +98,8 @@ export class NgForm extends ControlContainer implements Form { composeAsyncValidators(asyncValidators)); } + get submitted(): boolean { return this._submitted; } + get formDirective(): Form { return this; } get control(): ControlGroup { return this.form; } @@ -158,6 +162,7 @@ export class NgForm extends ControlContainer implements Form { } onSubmit(): boolean { + this._submitted = true; ObservableWrapper.callEmit(this.ngSubmit, null); return false; } diff --git a/modules/@angular/common/src/forms/directives/ng_form_model.ts b/modules/@angular/common/src/forms/directives/ng_form_model.ts index 8b654161e0..6067ea020e 100644 --- a/modules/@angular/common/src/forms/directives/ng_form_model.ts +++ b/modules/@angular/common/src/forms/directives/ng_form_model.ts @@ -107,6 +107,8 @@ export const formDirectiveProvider: any = }) export class NgFormModel extends ControlContainer implements Form, OnChanges { + private _submitted: boolean = false; + form: ControlGroup = null; directives: NgControl[] = []; ngSubmit = new EventEmitter(); @@ -131,6 +133,8 @@ export class NgFormModel extends ControlContainer implements Form, this._updateDomValue(); } + get submitted(): boolean { return this._submitted; } + get formDirective(): Form { return this; } get control(): ControlGroup { return this.form; } @@ -166,6 +170,7 @@ export class NgFormModel extends ControlContainer implements Form, } onSubmit(): boolean { + this._submitted = true; ObservableWrapper.callEmit(this.ngSubmit, null); return false; } diff --git a/modules/@angular/common/test/forms/integration_spec.ts b/modules/@angular/common/test/forms/integration_spec.ts index 371f87f813..3a65372c55 100644 --- a/modules/@angular/common/test/forms/integration_spec.ts +++ b/modules/@angular/common/test/forms/integration_spec.ts @@ -145,6 +145,55 @@ export function main() { expect(fixture.debugElement.componentInstance.name).toEqual('updated'); }))); + it("should mark NgForm as submitted on submit event", + inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => { + var t = `