fix(forms): emit value changes after errors and status are set
Closes #4714
This commit is contained in:
parent
6436f96fd1
commit
b716d2335b
@ -107,13 +107,13 @@ export class AbstractControl {
|
|||||||
|
|
||||||
this._updateValue();
|
this._updateValue();
|
||||||
|
|
||||||
|
this._errors = this.validator(this);
|
||||||
|
this._status = isPresent(this._errors) ? INVALID : VALID;
|
||||||
|
|
||||||
if (emitEvent) {
|
if (emitEvent) {
|
||||||
ObservableWrapper.callNext(this._valueChanges, this._value);
|
ObservableWrapper.callNext(this._valueChanges, this._value);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._errors = this.validator(this);
|
|
||||||
this._status = isPresent(this._errors) ? INVALID : VALID;
|
|
||||||
|
|
||||||
if (isPresent(this._parent) && !onlySelf) {
|
if (isPresent(this._parent) && !onlySelf) {
|
||||||
this._parent.updateValueAndValidity({onlySelf: onlySelf, emitEvent: emitEvent});
|
this._parent.updateValueAndValidity({onlySelf: onlySelf, emitEvent: emitEvent});
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
} from 'angular2/testing_internal';
|
} from 'angular2/testing_internal';
|
||||||
import {ControlGroup, Control, ControlArray, Validators} from 'angular2/core';
|
import {ControlGroup, Control, ControlArray, Validators} from 'angular2/core';
|
||||||
import {ObservableWrapper} from 'angular2/src/core/facade/async';
|
import {ObservableWrapper} from 'angular2/src/core/facade/async';
|
||||||
|
import {IS_DART} from '../../platform';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe("Form Model", () => {
|
describe("Form Model", () => {
|
||||||
@ -116,7 +117,7 @@ export function main() {
|
|||||||
describe("valueChanges", () => {
|
describe("valueChanges", () => {
|
||||||
var c;
|
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",
|
it("should fire an event after the value has been updated",
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
@ -128,6 +129,19 @@ export function main() {
|
|||||||
c.updateValue("new");
|
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) => {
|
it("should return a cold observable", inject([AsyncTestCompleter], (async) => {
|
||||||
c.updateValue("will be ignored");
|
c.updateValue("will be ignored");
|
||||||
ObservableWrapper.subscribe(c.valueChanges, (value) => {
|
ObservableWrapper.subscribe(c.valueChanges, (value) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user