While saving all my grid rows, I need to check whether there is a duplicate for a specific column field
(this.formGroups.get('items') as FormArray).controls.forEach((item) => {
console.log(item.value.attributeDisplayName);
});
I need to stop the form from submission by showing an alert or something similar when there is a duplicate value for attributeDisplayName. How can I check that in the current forEach loop. Thanks
I am using kendo angular components in my HTML markup and I am not using form tag. Below is an example for column declaration
<kendo-grid-column field="attributeDisplayName" title="CUSTOM FIELD LABEL" width="190">
<ng-template kendoGridEditTemplate let-column="column" let-formGroup="formGroup" >
<input ngDefaultControl class="k-textbox" [formControl]="formGroup.get(column.field)">
<div *ngIf="formGroup.get(column.field).errors && (formGroup.get(column.field).dirty || formGroup.get(column.field).touched)">
<span style="color:red" class="k-icon k-i-warning"></span>
<span style="color:red">CUSTOM FIELD LABEL is a required field</span>
</div>
</ng-template>
</kendo-grid-column>
Below is FormGroup declartion in .ts file
public formGroup: FormGroup;
public formGroups: FormGroup = new FormGroup({ items: new FormArray([]) });
public createFormGroup = (dataItem) =>
new FormGroup({
atrributeId: new FormControl(dataItem.atrributeId),
objectType: new FormControl(dataItem.objectType, Validators.required),
attributeDisplayName: new FormControl(dataItem.attributeDisplayName, Validators.required),
dataType: new FormControl(dataItem.dataType, Validators.required),
inputValues: new FormControl(dataItem.inputValues, [Validators.required, InputValuesValidator]),
isGridEligible: new FormControl(dataItem.isGridEligible, Validators.required),
isInvoiceEligible: new FormControl(dataItem.isInvoiceEligible, Validators.required),
});
An example function where I use this FormGroup
public editRows(grid) {
this.isEdited = true;
let currentRow = 0;
let rows: any = grid.data.data;
for (let i = 0; i < rows.length; i++) {
const formGroup = this.createFormGroup(rows[i]);
this.formGroup = formGroup;
(this.formGroups.get('items') as FormArray).push(formGroup);
grid.editRow(currentRow, formGroup, {skipFocus: true});
currentRow++;
}
}