Skip to content

Commit

Permalink
[DURACOM-297] fix changing values in submission form after ordering
Browse files Browse the repository at this point in the history
(cherry picked from commit 1c92721)
  • Loading branch information
Andrea Barbasso authored and github-actions[bot] committed Dec 19, 2024
1 parent a8e658a commit abc3c41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<!-- Draggable Container -->
<div cdkDropList cdkDropListLockAxis="y" (cdkDropListDropped)="moveSelection($event)">
<!-- Draggable Items -->
<div *ngFor="let groupModel of model.groups; let idx = index"
<div *ngFor="let groupModel of model.groups"
role="group"
[formGroupName]="idx"
[formGroupName]="groupModel.index"
[ngClass]="[getClass('element', 'group'), getClass('grid', 'group')]"
cdkDrag
[cdkDragDisabled]="dragDisabled"
Expand All @@ -25,7 +25,7 @@
[formGroup]="group"
[formModel]="formModel"
[context]="groupModel"
[group]="control.get([idx])"
[group]="getControlOfGroup(groupModel)"
[hidden]="_model.hidden"
[class.d-none]="_model.hidden"
[layout]="formLayout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,17 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent {
get dragDisabled(): boolean {
return this.model.groups.length === 1 || !this.model.isDraggable;
}

/**
* Gets the control of the specified group model. It adds the startingIndex property to the group model if it does not
* already have it. This ensures that the controls are always linked to the correct group model.
* @param groupModel The group model to get the control for.
* @returns The form control of the specified group model.
*/
getControlOfGroup(groupModel: any) {
if (!groupModel.hasOwnProperty('startingIndex')) {
groupModel.startingIndex = groupModel.index;

Check warning on line 93 in src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts#L93

Added line #L93 was not covered by tests
}
return this.control.get([groupModel.startingIndex]);

Check warning on line 95 in src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.ts#L95

Added line #L95 was not covered by tests
}
}

0 comments on commit abc3c41

Please sign in to comment.