I have a simple Reactive Form in Angular 2 and my form doesn't detect change of cells of a primeng data table. The html is:
<form [formGroup]="myForm" novalidate (ngSubmit)="onSubmit()">
<p-dataTable [value]="dataMenu" [editable]="true" formArrayName="menu">
<p-column field="menu" header="Menu"></p-column>
<p-column field="price" header="Price" [editable]="true">
<template let-row="rowData" let-i="rowIndex" pTemplate="body">
{{row.price}}
</template>
<template let-row="rowData" let-i="rowIndex" pTemplate="editor">
<input type="number" pInputText [(ngModel)]="row.price" name="test" [ngModelOptions]="{standalone: true}"/>
</template>
</p-column>
</p-dataTable>
and the .ts file is:
this.myForm = this.fb.group( { //fb is FormBuilder
menu: this.fb.array([]),
});
this.setDataMenu(this.dataMenu);
...
setDataMenu( menu: Array<any> ) {
const control = <FormArray>this.myForm.controls['menu'];
for ( let m of menu ) {
control.push( this.fb.control(m, validatePrices) );
}
}
function validatePrices( c: FormControl ) {
return ( c.value != null && c.value.price) ? null : {
validatePrices: {
valid: false
}
};
}
The problem is that the validation fires only at the beginning and when the value of "dataMenu" changes, the form does not detect this change.