Disabled form form.value shows all controls, as opposed to partially disabled form which shows only enabled controls.
See original GitHub issueBug Report
Affected Package
@angular/forms - Angular 12
Minimal Reproduction
- Create a reactive form group with 2+ controls.
- Add
<pre>{{form.value | json}}</pre>
to the html. - Disable one control => form.value shows only the other enabled control. (Correct behavior. It hides the disabled controls.)
- Disable all controls (e.g., using form.disable()) => form.value shows both controls, instead of being empty. (Incorrect behavior.)
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is described in the docs
https://angular.io/api/forms/AbstractControl#value
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 the
form.disabled
property before reading theform.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