fix(forms): do not reset the value of the input when it came from the view

This commit is contained in:
vsavkin
2015-07-15 18:16:50 -07:00
parent b1df54501a
commit b1231593b6
11 changed files with 81 additions and 34 deletions
@@ -721,6 +721,33 @@ export function main() {
});
}));
});
describe("ng-model corner cases", () => {
it("should not update the view when the value initially came from the view",
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var form = new Control("");
var t =
`<div><input type="text" [ng-form-control]="form" [(ng-model)]="name"></div>`;
var rootTC;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
tick();
rootTC.componentInstance.form = form;
rootTC.detectChanges();
var input = rootTC.query(By.css("input")).nativeElement;
input.value = "aa";
input.selectionStart = 1;
dispatchEvent(input, "change");
tick();
rootTC.detectChanges();
// selection start has not changed because we did not reset the value
expect(input.selectionStart).toEqual(1);
})));
});
});
}