New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled controls from FormGroup (part of component that implements ControlValueAccessor) are excluded by .getRawValue() on parent. #28070

Open
kvitozev opened this Issue Jan 11, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@kvitozev
Copy link

kvitozev commented Jan 11, 2019

馃悶 bug report

Affected Package

This issue is caused by package @angular/forms

Is this a regression?

N/A

Description

Having a component that implements ControlValueAccessor, with internal FormGroup to maintain the state of custom form control. When any field, that's part of that FormGroup is disabled, the field isn't visible when calling .getRawValue() method in parent form (i.e. .getRawValue() === .value) . By specification, getRawValue() should return the raw object, including disabled fields.

馃敩 Minimal Reproduction

Examine the output of .value and .getRawValue() when clicking enable/disable button on the nested form.

https://stackblitz.com/edit/angular-nested-reactive-form-jjgkef

馃敟 Exception or Error

When given form control (part of FormGroup, that acts like custom form control) is disabled, the .getRawValue() should return the raw object with all fields, including disabled ones.

馃實 Your Environment

Angular Version:

Angular CLI: 1.7.0
Node: 10.14.1
OS: win32 x64
Angular: 5.2.4
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router

@angular/cdk: 5.2.5
@angular/cli: 1.7.0
@angular/flex-layout: 5.0.0-beta.14
@angular/material-moment-adapter: 6.3.0
@angular/material: 5.2.5
@angular-devkit/build-optimizer: 0.3.1
@angular-devkit/core: 0.4.6
@angular-devkit/schematics: 0.3.1
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.0
@schematics/angular: 0.3.1
@schematics/package-update: 0.3.1
typescript: 2.4.2
webpack: 3.11.0

@kvitozev kvitozev changed the title Disabled controls from FormGroup (part of component that implements ControlValueAccessor) are excluded by .getRawValue() response. Disabled controls from FormGroup (part of component that implements ControlValueAccessor) are excluded by .getRawValue() on parent. Jan 11, 2019

@kvitozev

This comment has been minimized.

Copy link

kvitozev commented Jan 11, 2019

In the source code of getRawValue(), I can see the following:

  getRawValue(): any {
    return this._reduceChildren(
        {}, (acc: {[k: string]: AbstractControl}, control: AbstractControl, name: string) => {
          acc[name] = control instanceof FormControl ? control.value : (<any>control).getRawValue();
          return acc;
        });
  }

So, whenever we have custom form control (its instance of FormControl, correct?) Angular is retrieving .value property.

Is there any workaround? Can we consider this as issue?

@ngbot ngbot bot added this to the needsTriage milestone Jan 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment