Skip to content

Commit

Permalink
fix(forms): scope value accessors, validators, and async validators t…
Browse files Browse the repository at this point in the history
…o self

Closes #5440
  • Loading branch information
vsavkin committed Nov 23, 2015
1 parent 230aad4 commit ba64b5e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Host,
SkipSelf,
forwardRef,
Provider
Provider,
Self
} from 'angular2/core';
import {CONST_EXPR} from 'angular2/src/facade/lang';

Expand Down Expand Up @@ -80,8 +81,8 @@ export class NgControlGroup extends ControlContainer implements OnInit,
_parent: ControlContainer;

constructor(@Host() @SkipSelf() parent: ControlContainer,
@Optional() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
super();
this._parent = parent;
}
Expand Down
10 changes: 6 additions & 4 deletions modules/angular2/src/common/forms/directives/ng_control_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
SkipSelf,
Provider,
Inject,
Optional
Optional,
Self
} from 'angular2/core';

import {ControlContainer} from './control_container';
Expand Down Expand Up @@ -103,11 +104,12 @@ export class NgControlName extends NgControl implements OnChanges,
private _added = false;

constructor(@Host() @SkipSelf() private _parent: ControlContainer,
@Optional() @Inject(NG_VALIDATORS) private _validators:
@Optional() @Self() @Inject(NG_VALIDATORS) private _validators:
/* Array<Validator|Function> */ any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
/* Array<Validator|Function> */ any[],
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) {
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
valueAccessors: ControlValueAccessor[]) {
super();
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
Expand Down
6 changes: 3 additions & 3 deletions modules/angular2/src/common/forms/directives/ng_form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'angular2/src/facade/async';
import {StringMapWrapper, ListWrapper} from 'angular2/src/facade/collection';
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 {Form} from './form_interface';
import {NgControlGroup} from './ng_control_group';
Expand Down Expand Up @@ -90,8 +90,8 @@ export class NgForm extends ControlContainer implements Form {
form: ControlGroup;
ngSubmit = new EventEmitter();

constructor(@Optional() @Inject(NG_VALIDATORS) validators: any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) {
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[],
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) {
super();
this.form = new ControlGroup({}, null, composeValidators(validators),
composeAsyncValidators(asyncValidators));
Expand Down
10 changes: 6 additions & 4 deletions modules/angular2/src/common/forms/directives/ng_form_control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
forwardRef,
Provider,
Inject,
Optional
Optional,
Self
} from 'angular2/core';
import {NgControl} from './ng_control';
import {Control} from '../model';
Expand Down Expand Up @@ -86,11 +87,12 @@ export class NgFormControl extends NgControl implements OnChanges {
model: any;
viewModel: any;

constructor(@Optional() @Inject(NG_VALIDATORS) private _validators:
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators:
/* Array<Validator|Function> */ any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators:
/* Array<Validator|Function> */ any[],
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) {
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
valueAccessors: ControlValueAccessor[]) {
super();
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
Expand Down
7 changes: 4 additions & 3 deletions modules/angular2/src/common/forms/directives/ng_form_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
forwardRef,
Provider,
Inject,
Optional
Optional,
Self
} from 'angular2/core';
import {NgControl} from './ng_control';
import {NgControlGroup} from './ng_control_group';
Expand Down Expand Up @@ -107,8 +108,8 @@ export class NgFormModel extends ControlContainer implements Form,
directives: NgControl[] = [];
ngSubmit = new EventEmitter();

constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[]) {
super();
}

Expand Down
10 changes: 6 additions & 4 deletions modules/angular2/src/common/forms/directives/ng_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
forwardRef,
Provider,
Inject,
Optional
Optional,
Self
} from 'angular2/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
import {NgControl} from './ng_control';
Expand Down Expand Up @@ -62,9 +63,10 @@ export class NgModel extends NgControl implements OnChanges {
model: any;
viewModel: any;

constructor(@Optional() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[],
@Optional() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) {
constructor(@Optional() @Self() @Inject(NG_VALIDATORS) private _validators: any[],
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) private _asyncValidators: any[],
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
valueAccessors: ControlValueAccessor[]) {
super();
this.valueAccessor = selectValueAccessor(this, valueAccessors);
}
Expand Down

0 comments on commit ba64b5e

Please sign in to comment.