diff --git a/modules/angular2/src/core/forms/model.ts b/modules/angular2/src/core/forms/model.ts index f88c54897f..0df3829ed1 100644 --- a/modules/angular2/src/core/forms/model.ts +++ b/modules/angular2/src/core/forms/model.ts @@ -107,13 +107,13 @@ export class AbstractControl { this._updateValue(); + this._errors = this.validator(this); + this._status = isPresent(this._errors) ? INVALID : VALID; + if (emitEvent) { ObservableWrapper.callNext(this._valueChanges, this._value); } - this._errors = this.validator(this); - this._status = isPresent(this._errors) ? INVALID : VALID; - if (isPresent(this._parent) && !onlySelf) { this._parent.updateValueAndValidity({onlySelf: onlySelf, emitEvent: emitEvent}); } diff --git a/modules/angular2/test/core/forms/model_spec.ts b/modules/angular2/test/core/forms/model_spec.ts index b25fa7ad32..39e857ad59 100644 --- a/modules/angular2/test/core/forms/model_spec.ts +++ b/modules/angular2/test/core/forms/model_spec.ts @@ -15,6 +15,7 @@ import { } from 'angular2/testing_internal'; import {ControlGroup, Control, ControlArray, Validators} from 'angular2/core'; import {ObservableWrapper} from 'angular2/src/core/facade/async'; +import {IS_DART} from '../../platform'; export function main() { describe("Form Model", () => { @@ -116,7 +117,7 @@ export function main() { describe("valueChanges", () => { var c; - beforeEach(() => { c = new Control("old"); }); + beforeEach(() => { c = new Control("old", Validators.required); }); it("should fire an event after the value has been updated", inject([AsyncTestCompleter], (async) => { @@ -128,6 +129,19 @@ export function main() { c.updateValue("new"); })); + // TODO: remove the if statement after making observable delivery sync + if (!IS_DART) { + it("should update set errors and status before emitting an event", + inject([AsyncTestCompleter], (async) => { + c.valueChanges.toRx().subscribe(value => { + expect(c.valid).toEqual(false); + expect(c.errors).toEqual({"required": true}); + async.done(); + }); + c.updateValue(""); + })); + } + it("should return a cold observable", inject([AsyncTestCompleter], (async) => { c.updateValue("will be ignored"); ObservableWrapper.subscribe(c.valueChanges, (value) => {