Home > database >  How to get disabled checkbox in form.value
How to get disabled checkbox in form.value

Time:09-27

I am adding multiple check box in my form and while adding the control into form, for some check box I have set disable attribute value as true.

    this.myform.addControl('checkBox1'),
  new FormControl({
    value: true,
    disabled: true,
  })
);

   this.myform.addControl('checkBox2'),
  new FormControl({
    value: true,
    disabled: false,
  })
);

so both checkbox are added as checked and one is disable and one is enable. Now while getting the value using this.myform.value, not getting the disabled checkBox1. Getting only one check box which is checkBox2.

So please let me know to get checkBox1 also in this.myform.value

CodePudding user response:

Angular formGroup.value will not returns the disabled controls values, instead you can use formGroup.getRawValue() it will include all your form controls including disabled.

this.myform.value  // returns only enabled controls

Instead use below code on your code to get disabled fields value.

this.myform.getRawValue();  // returns the all form controls value and include disabled controls too

CodePudding user response:

You can explicitly fetch the value of the controls that you require like this

this.myform.controls.checkBox1.value //disabled checkbox
  • Related