fix(forms): scope value accessors, validators, and async validators to self

Closes #5440
This commit is contained in:
vsavkin 2015-11-23 10:03:56 -08:00 committed by Victor Savkin
parent 230aad4047
commit ba64b5ea5a
6 changed files with 29 additions and 21 deletions

View File

@ -7,7 +7,8 @@ import {
Host, Host,
SkipSelf, SkipSelf,
forwardRef, forwardRef,
Provider Provider,
Self
} from 'angular2/core'; } from 'angular2/core';
import {CONST_EXPR} from 'angular2/src/facade/lang'; import {CONST_EXPR} from 'angular2/src/facade/lang';
@ -80,8 +81,8 @@ export class NgControlGroup extends ControlContainer implements OnInit,
_parent: ControlContainer; _parent: ControlContainer;
constructor(@Host() @SkipSelf() parent: ControlContainer, constructor(@Host() @SkipSelf() parent: ControlContainer,
@Optional() @Inject(NG_VALIDATORS) private _validators: any[], @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
super(); super();
this._parent = parent; this._parent = parent;
} }

View File

@ -12,7 +12,8 @@ import {
SkipSelf, SkipSelf,
Provider, Provider,
Inject, Inject,
Optional Optional,
Self
} from 'angular2/core'; } from 'angular2/core';
import {ControlContainer} from './control_container'; import {ControlContainer} from './control_container';
@ -103,11 +104,12 @@ export class NgControlName extends NgControl implements OnChanges,
private _added = false; private _added = false;
constructor(@Host() @SkipSelf() private _parent: ControlContainer, constructor(@Host() @SkipSelf() private _parent: ControlContainer,
@Optional() @Inject(NG_VALIDATORS) private _validators: @Optional() @Self() @Inject(NG_VALIDATORS) private _validators:
/* Array<Validator|Function> */ any[], /* Array<Validator|Function> */ any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
/* Array<Validator|Function> */ any[], /* Array<Validator|Function> */ any[],
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { @Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
valueAccessors: ControlValueAccessor[]) {
super(); super();
this.valueAccessor = selectValueAccessor(this, valueAccessors); this.valueAccessor = selectValueAccessor(this, valueAccessors);
} }

View File

@ -6,7 +6,7 @@ import {
} from 'angular2/src/facade/async'; } from 'angular2/src/facade/async';
import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection'; import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang'; import {isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang';
import {Directive, forwardRef, Provider, Optional, Inject} from 'angular2/core'; import {Directive, forwardRef, Provider, Optional, Inject, Self} from 'angular2/core';
import {NgControl} from './ng_control'; import {NgControl} from './ng_control';
import {Form} from './form_interface'; import {Form} from './form_interface';
import {NgControlGroup} from './ng_control_group'; import {NgControlGroup} from './ng_control_group';
@ -90,8 +90,8 @@ export class NgForm extends ControlContainer implements Form {
form: ControlGroup; form: ControlGroup;
ngSubmit = new EventEmitter(); ngSubmit = new EventEmitter();
constructor(@Optional() @Inject(NG_VALIDATORS) validators: any[], constructor(@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) { @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) {
super(); super();
this.form = new ControlGroup({}, null, composeValidators(validators), this.form = new ControlGroup({}, null, composeValidators(validators),
composeAsyncValidators(asyncValidators)); composeAsyncValidators(asyncValidators));

View File

@ -9,7 +9,8 @@ import {
forwardRef, forwardRef,
Provider, Provider,
Inject, Inject,
Optional Optional,
Self
} from 'angular2/core'; } from 'angular2/core';
import {NgControl} from './ng_control'; import {NgControl} from './ng_control';
import {Control} from '../model'; import {Control} from '../model';
@ -86,11 +87,12 @@ export class NgFormControl extends NgControl implements OnChanges {
model: any; model: any;
viewModel: any; viewModel: any;
constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators:
/* Array<Validator|Function> */ any[], /* Array<Validator|Function> */ any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
/* Array<Validator|Function> */ any[], /* Array<Validator|Function> */ any[],
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { @Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
valueAccessors: ControlValueAccessor[]) {
super(); super();
this.valueAccessor = selectValueAccessor(this, valueAccessors); this.valueAccessor = selectValueAccessor(this, valueAccessors);
} }

View File

@ -8,7 +8,8 @@ import {
forwardRef, forwardRef,
Provider, Provider,
Inject, Inject,
Optional Optional,
Self
} from 'angular2/core'; } from 'angular2/core';
import {NgControl} from './ng_control'; import {NgControl} from './ng_control';
import {NgControlGroup} from './ng_control_group'; import {NgControlGroup} from './ng_control_group';
@ -107,8 +108,8 @@ export class NgFormModel extends ControlContainer implements Form,
directives: NgControl[] = []; directives: NgControl[] = [];
ngSubmit = new EventEmitter(); ngSubmit = new EventEmitter();
constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: any[], constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) { @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
super(); super();
} }

View File

@ -8,7 +8,8 @@ import {
forwardRef, forwardRef,
Provider, Provider,
Inject, Inject,
Optional Optional,
Self
} from 'angular2/core'; } from 'angular2/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
import {NgControl} from './ng_control'; import {NgControl} from './ng_control';
@ -62,9 +63,10 @@ export class NgModel extends NgControl implements OnChanges {
model: any; model: any;
viewModel: any; viewModel: any;
constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: any[], constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[], @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[],
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) { @Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
valueAccessors: ControlValueAccessor[]) {
super(); super();
this.valueAccessor = selectValueAccessor(this, valueAccessors); this.valueAccessor = selectValueAccessor(this, valueAccessors);
} }