diff --git a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.spec.ts b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.spec.ts index 0e834fc45a..42bd36abc0 100644 --- a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.spec.ts +++ b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.spec.ts @@ -728,8 +728,7 @@ describe('PoDynamicFormFieldsComponent: ', () => { const updatedFields = component['updateFieldContainer'](changes, containerFields); expect(updatedFields[0][0].container).toBe('updatedContainer1'); - expect(updatedFields[1][0].container).toBe('container2'); - expect(updatedFields[2][0].container).toBe('updatedContainer3'); + expect(updatedFields[1][0].container).toBe('updatedContainer3'); }); it('diffObjectsArray: should return the complete object if it is new in the array', () => { diff --git a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.ts b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.ts index 65d96e8f3b..ba8e370a84 100644 --- a/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.ts +++ b/projects/ui/src/lib/components/po-dynamic/po-dynamic-form/po-dynamic-form-fields/po-dynamic-form-fields.component.ts @@ -206,7 +206,7 @@ export class PoDynamicFormFieldsComponent extends PoDynamicFormFieldsBaseCompone this.containerFields = this.updateFieldContainer(result, this.containerFields); } - private updateFieldContainer(changes, containerFields) { + private updateFieldContainer(changes: Array, containerFields: Array>) { const mapchanges = new Map(changes.map(obj => [obj.property, obj])); containerFields.forEach(subArray => { @@ -218,7 +218,14 @@ export class PoDynamicFormFieldsComponent extends PoDynamicFormFieldsBaseCompone }); }); - return containerFields; + // Garante que apenas os items de `changes` estejam em `containerFields` + return containerFields + .map(itemFields => + itemFields.filter(formFieldContainer => + changes.some(formFieldChanges => formFieldContainer.property === formFieldChanges.property) + ) + ) + .filter(subArray => subArray.length > 0); } private diffObjectsArray(oldArray, newArray) {