fix(forms): support radio buttons with same name but diff parent (#11152)
Closes #10065
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
|
||||
import {AbstractControlDirective} from './abstract_control_directive';
|
||||
import {ControlContainer} from './control_container';
|
||||
import {ControlValueAccessor} from './control_value_accessor';
|
||||
import {AsyncValidatorFn, Validator, ValidatorFn} from './validators';
|
||||
|
||||
@@ -24,6 +25,8 @@ function unimplemented(): any {
|
||||
* @stable
|
||||
*/
|
||||
export abstract class NgControl extends AbstractControlDirective {
|
||||
/** @internal */
|
||||
_parent: ControlContainer = null;
|
||||
name: string = null;
|
||||
valueAccessor: ControlValueAccessor = null;
|
||||
/** @internal */
|
||||
|
||||
@@ -71,12 +71,13 @@ export class NgModel extends NgControl implements OnChanges,
|
||||
|
||||
@Output('ngModelChange') update = new EventEmitter();
|
||||
|
||||
constructor(@Optional() @Host() private _parent: ControlContainer,
|
||||
constructor(@Optional() @Host() parent: ControlContainer,
|
||||
@Optional() @Self() @Inject(NG_VALIDATORS) validators: Array<Validator|ValidatorFn>,
|
||||
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: Array<Validator|AsyncValidatorFn>,
|
||||
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR)
|
||||
valueAccessors: ControlValueAccessor[]) {
|
||||
super();
|
||||
this._parent = parent;
|
||||
this._rawValidators = validators || [];
|
||||
this._rawAsyncValidators = asyncValidators || [];
|
||||
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
||||
|
||||
@@ -53,7 +53,7 @@ export class RadioControlRegistry {
|
||||
controlPair: [NgControl, RadioControlValueAccessor],
|
||||
accessor: RadioControlValueAccessor): boolean {
|
||||
if (!controlPair[0].control) return false;
|
||||
return controlPair[0].control.root === accessor._control.control.root &&
|
||||
return controlPair[0]._parent === accessor._control._parent &&
|
||||
controlPair[1].name === accessor.name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,12 +109,13 @@ export class FormControlName extends NgControl implements OnChanges, OnDestroy {
|
||||
set isDisabled(isDisabled: boolean) { ReactiveErrors.disabledAttrWarning(); }
|
||||
|
||||
constructor(
|
||||
@Optional() @Host() @SkipSelf() private _parent: ControlContainer,
|
||||
@Optional() @Host() @SkipSelf() parent: ControlContainer,
|
||||
@Optional() @Self() @Inject(NG_VALIDATORS) validators: Array<Validator|ValidatorFn>,
|
||||
@Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators:
|
||||
Array<Validator|AsyncValidatorFn>,
|
||||
@Optional() @Self() @Inject(NG_VALUE_ACCESSOR) valueAccessors: ControlValueAccessor[]) {
|
||||
super();
|
||||
this._parent = parent;
|
||||
this._rawValidators = validators || [];
|
||||
this._rawAsyncValidators = asyncValidators || [];
|
||||
this.valueAccessor = selectValueAccessor(this, valueAccessors);
|
||||
|
||||
Reference in New Issue
Block a user