question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disabled form form.value shows all controls, as opposed to partially disabled form which shows only enabled controls.

See original GitHub issue

Bug Report

Affected Package

@angular/forms - Angular 12

Minimal Reproduction

  1. Create a reactive form group with 2+ controls.
  2. Add <pre>{{form.value | json}}</pre> to the html.
  3. Disable one control => form.value shows only the other enabled control. (Correct behavior. It hides the disabled controls.)
  4. Disable all controls (e.g., using form.disable()) => form.value shows both controls, instead of being empty. (Incorrect behavior.)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
destus90commented, Jun 23, 2021

This is described in the docs

https://angular.io/api/forms/AbstractControl#value

For a disabled FormGroup, the values of all controls as an object with a key-value pair for each member of the group.

1reaction
petebacondarwincommented, Jun 23, 2021

This is working as expected. When a form is disabled its value still includes all its children’s values in its value property. When all a form’s children are disabled, then the form is implicitly disabled itself. So again will include all the values of the disabled children.

You can check theform.disabled property before reading the form.value property if you want a different value for the form when it is disabled.

See https://stackblitz.com/edit/angular-zrstua-lcsktg?file=src%2Fapp%2Finput-errors-example.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2 disabled controls do not get included in the form.value
Notice how the disabled controls are excluded. My intent is that when the form changes I want to be able to pass the...
Read more >
Disabling Form Controls When Working With Reactive Forms ...
Instantiate a new FormControl with the disabled property set to true. FormControl({value: '', disabled: true}) . Calling control.disable() or control.enable() .
Read more >
HTML attribute: disabled - HTML: HyperText Markup Language
The Boolean disabled attribute, when present, makes the element not mutable, focusable, or even submitted with the form.
Read more >
Typed Forms - Angular
On any FormGroup , it is possible to disable controls. Any disabled control will not appear in the group's value. As a consequence,...
Read more >
Why are form-related commands or controls on the ribbon ...
You might be trying to add an ActiveX control in a document that was signed by an untrusted publisher. The Properties command Button...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found