Search code examples
angularformsdisabled-control

How to get disabled checkbox in form.value


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


Solution

  • 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