Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable the entire form at once (Angular reactive form)

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?

like image 283
YD_ Avatar asked Aug 24 '17 06:08

YD_


People also ask

How do I disable all fields in FormGroup?

just add css query to find all input:disabled, textarea:disabled and etc.

Can we disable form in angular?

Angular tells you that it's better for you to use the ways it gives you to disable/enable form controls. You can enable/disable a form control by using the following ways: Instantiate a new FormControl with the disabled property set to true. FormControl({value: '', disabled: true}) .

How do I turn off form control and keep value?

If you set disabled to true when you set up this control in your component class, the disabled attribute will actually be set in the DOM for you. We recommend using this approach to avoid 'changed after checked' errors. Example: form = new FormGroup({ first: new FormControl({value: 'Nancy', disabled: true}, Validators.


1 Answers

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

like image 178
Rahul Singh Avatar answered Sep 28 '22 13:09

Rahul Singh