RC6 Forms: Calling disabled() on FormControl makes entire form invalid
See original GitHub issueI’m submitting a … (check one with “x”)
[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
If I call this.myForm.controls["code"].disable();
, this.myForm.valid
is always false
:
this.myForm.patchValue({code: 17});
console.log(this.myForm.valid);
this.myForm.controls["code"].disable();
console.log(this.myForm.valid);
This outputs
true
false
Expected/desired behavior The form should still be valid, even though the control has been disabled.
Reproduction of the problem http://plnkr.co/edit/B8cA0zzcrt4SjxrGMlRf?p=preview
- Angular version: 2.0.0-rc.6
- Browser: [Chrome 53.0.2785.92 | Firefox 48 ]
- Language: [TypeScript 1.8]
- Remarks
I initially remarked this as a comment in #11271, but I don’t want to hijack the other issue, which is about dynamically binding [disabled]
.
It could be that PR #11257 fixes this already, but I am not sure, so I decided to file this bug-report.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:10 (3 by maintainers)
Top Results From Across the Web
angular - Reactive forms - disabled attribute - Stack Overflow
I have been using [attr.disabled] because I still like this template driven than programmatic enable()/disable() as it is superior IMO.
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 >Angular Custom Form Controls - Complete Guide
In this guide, we are going to learn exactly how to take an existing custom form control component and make it fully compatible...
Read more >FormGroup - Angular
Tracks the value and validity state of a group of FormControl instances. ... For example, if one of the controls in a group...
Read more >Angular 6: Disabling Input On Reactive Form Without ...
Each batch can contain several Using Angular Reactive Forms FormArray we can ... RC6 Forms: Calling disabled on FormControl makes entire form RC6...
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 Free
Top 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
I’ve just stubbed this custom directive, which should behave as desidered. Warning: it’s just a proof-of-concept, not a complete solution. Feedbacks are welcome, of course.
[copied from #11257]
@capi The way the model works is that a parent form group is disabled if all its child controls are disabled. The status of group controls is always calculated as a reduction of the child controls.
In your example, your form only has one form control. Once you disable it, you are effectively disabling the whole form because all its (one) children are disabled. If you log the status of the form, you’ll see that its status is ‘DISABLED’, which is why valid is false. The statuses are mutually exclusive. Closing, as this works as designed.