On controlArray.push(new FormGroup) unable to enable() the previous form group control

Viewed 158

I am facing issue regarding a scenario say.

When I add a new control to array using controlArray.push(new FormGroup), I am unable to use enable() for the previous form group control as STATUS is "VALID" always where as if I don't push any new FormGroup I am able to edit status to 'DISABLED' using disable(). I need to actually edit my initial form group controls along with new one added.

Please guide me with a way!

const controlArray = this.editPostForm.get('formArrayName') as FormArray;
controlArray.push(
  this.fb.group({
    id: new FormControl({ value: '', disabled: true }),
    authors: new FormControl({ value: '', disabled: true }),
    metaData: new FormControl({ value: '', disabled: true }))
  })
);
toggleEdit(i) {
const controlArray = this.editPostForm.get('formArrayName') as FormArray;
controlArray.controls[i].enable();
}

Fields are enabled for editing.But on pushing same form group again toggleEdit() for previous form group controls doesnt not enable fields.
Control Array for previous formGroup always retains Status to be "VALID' and enabled = 'true' although my fields are enabled onclick toggleEdit()
0 Answers
Related