32

Is there any way to disable the entire form in angular when using Reactive forms. I know it is possible to make them disable one by one.

 this.tempForm = this.fb.group({
  m26_type:  '',
  m26_name:  ''
 })
this.tempForm.get('m26_type').disable();

Is it possible to disable the whole form rather than make every controller disable separately?

YD_
  • 735
  • 2
  • 7
  • 17
  • 1
    Have a look at [AbstractControl.disable](https://angular.io/api/forms/AbstractControl#disable) – Philipp Aug 24 '17 at 06:04

1 Answers1

41
this.tempForm.disable();

Disables the control. This means the control will be exempt from validation checks and excluded from the aggregate value of any parent. Its status is DISABLED.

If the control has children, all children will be disabled to maintain the model.

LINK

UPDATE

Plunker link - https://plnkr.co/edit/CFC4uKpvfE4otJ2PWdkc?p=preview

Rahul Singh
  • 16,265
  • 5
  • 49
  • 74
  • @Freak001 updated the code with a plunker link check that – Rahul Singh Aug 24 '17 at 06:20
  • @Freak001 jope it helped ? – Rahul Singh Aug 24 '17 at 06:26
  • 2
    Yeah it helped. In my case problem was I am using custom form controls in reactive forms. When using custom form controls i reactive forms need to implement setDisabledState(). https://angular.io/api/forms/ControlValueAccessor – YD_ Feb 10 '18 at 17:23
  • 4
    Remember for template driven forms the code is ngFormName.form.disable() or enable(). Also they are functions as the properties 'disabled' and 'enabled' are read-only. – Meliovation Apr 03 '19 at 12:15