rajeev tejapuriya
rajeev tejapuriya

Reputation: 35

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

Upvotes: 2

Views: 886

Answers (2)

sasi66
sasi66

Reputation: 447

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

Upvotes: 3

HassanMoin
HassanMoin

Reputation: 2194

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

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

Upvotes: 0

Related Questions