I need help in making the rows enable only when the checkbox is check. The default rows should be disabled but when the checkbox is only check, that row will be enabled. Here's the link to my code
patchValues() {
let rows = this.myForm.get('rows') as FormArray;
this.orders.forEach(material => {
material.materials.forEach(x => {
rows.push(this.fb.group({
checkbox_value: [null],
material_id: new FormControl({value: x.id, disabled: true}, Validators.required),
material_name: x.name,
quantity: [null, Validators.required]
}))
})
})
}
Another aproach is create a directive
Then you can use like
Stack Blitz, Fork
[attr.disabled]="myForm.get('rows').value[i].checkbox_value ? null: ''"
attr.disabled
, here attr is for binding with properties which don't exist directly on an elementmyForm.get('rows').value[i].checkbox_value
, is fairly straight forward access to a form control's value.