Skip to content

Commit bb608d9

Browse files
Andrea Barbassogithub-actions[bot]
authored andcommitted
[DURACOM-297] fix changing values in submission form after ordering
(cherry picked from commit 1c92721)
1 parent 6bcac36 commit bb608d9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/app/shared/form/builder/ds-dynamic-form-ui/models/array-group/dynamic-form-array.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<!-- Draggable Container -->
88
<div cdkDropList cdkDropListLockAxis="y" (cdkDropListDropped)="moveSelection($event)">
99
<!-- Draggable Items -->
10-
<div *ngFor="let groupModel of model.groups; let idx = index"
10+
<div *ngFor="let groupModel of model.groups"
1111
role="group"
12-
[formGroupName]="idx"
12+
[formGroupName]="groupModel.index"
1313
[ngClass]="[getClass('element', 'group'), getClass('grid', 'group')]"
1414
cdkDrag
1515
[cdkDragDisabled]="dragDisabled"
@@ -25,7 +25,7 @@
2525
[formGroup]="group"
2626
[formModel]="formModel"
2727
[context]="groupModel"
28-
[group]="control.get([idx])"
28+
[group]="getControlOfGroup(groupModel)"
2929
[hidden]="_model.hidden"
3030
[class.d-none]="_model.hidden"
3131
[layout]="formLayout"

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,17 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent {
114114
get dragDisabled(): boolean {
115115
return this.model.groups.length === 1 || !this.model.isDraggable;
116116
}
117+
118+
/**
119+
* Gets the control of the specified group model. It adds the startingIndex property to the group model if it does not
120+
* already have it. This ensures that the controls are always linked to the correct group model.
121+
* @param groupModel The group model to get the control for.
122+
* @returns The form control of the specified group model.
123+
*/
124+
getControlOfGroup(groupModel: any) {
125+
if (!groupModel.hasOwnProperty('startingIndex')) {
126+
groupModel.startingIndex = groupModel.index;
127+
}
128+
return this.control.get([groupModel.startingIndex]);
129+
}
117130
}

0 commit comments

Comments
 (0)