feat(forms): add the submitted flag to NgForm and NgFormModel directives
Closes #2960 Closes #7449
This commit is contained in:

committed by
Misko Hevery

parent
89f61087c7
commit
420e83a396
@ -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 = `<div>
|
||||
<form #f="ngForm" (ngSubmit)="data=f.submitted"></form>
|
||||
<span>{{data}}</span>
|
||||
</div>`;
|
||||
|
||||
var fixture: ComponentFixture<MyComp8>;
|
||||
|
||||
tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then(
|
||||
(root) => { fixture = root; });
|
||||
tick();
|
||||
|
||||
fixture.debugElement.componentInstance.data = false;
|
||||
|
||||
tick();
|
||||
|
||||
var form = fixture.debugElement.query(By.css("form"));
|
||||
dispatchEvent(form.nativeElement, "submit");
|
||||
|
||||
tick();
|
||||
expect(fixture.debugElement.componentInstance.data).toEqual(true);
|
||||
})));
|
||||
|
||||
it("should mark NgFormModel as submitted on submit event",
|
||||
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
|
||||
var t = `<div>
|
||||
<form #f="ngForm" [ngFormModel]="form" (ngSubmit)="data=f.submitted"></form>
|
||||
<span>{{data}}</span>
|
||||
</div>`;
|
||||
|
||||
var fixture: ComponentFixture<MyComp8>;
|
||||
|
||||
tcb.overrideTemplate(MyComp8, t).createAsync(MyComp8).then(
|
||||
(root) => { fixture = root; });
|
||||
tick();
|
||||
|
||||
fixture.debugElement.componentInstance.form = new ControlGroup({});
|
||||
fixture.debugElement.componentInstance.data = false;
|
||||
|
||||
tick();
|
||||
|
||||
var form = fixture.debugElement.query(By.css("form"));
|
||||
dispatchEvent(form.nativeElement, "submit");
|
||||
|
||||
tick();
|
||||
expect(fixture.debugElement.componentInstance.data).toEqual(true);
|
||||
})));
|
||||
|
||||
it("should work with single controls",
|
||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||
var control = new Control("loginValue");
|
||||
|
Reference in New Issue
Block a user