Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2: Disabled Form Control's values not found in FormGroup.value

Tags:

angular

I have:

this.editMemberForm = this.formBuilder.group({
  name: [{value: '', disabled: true}],
  id: [{value: '', disabled: true}],
  relType: ''
});

Then I set values to the disabled form controls:

this.editMemberForm.patchValue({
  name: 'Me',
  id: '000',
});

And in onSubmit():

console.log('Saving data', this.editMemberForm.value);
// { relType: '123' }

I need this.editMemberForm.value to be { name: "Me", id: '000', relType: "123" }.

like image 900
kyw Avatar asked Mar 23 '26 20:03

kyw


1 Answers

You can use getRawValue() to get disabled controls values back as well.

like image 130
JayChase Avatar answered Mar 26 '26 12:03

JayChase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!