Skip to content

Commit d578222

Browse files
authored
Merge pull request #3770 from DSpace/backport-3679-to-dspace-7_x
[Port dspace-7_x] #3678, #3217 - Fix ordering and changing values of repeatable inputs in submission form
2 parents a8e658a + abc3c41 commit d578222

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
@@ -81,4 +81,17 @@ export class DsDynamicFormArrayComponent extends DynamicFormArrayComponent {
8181
get dragDisabled(): boolean {
8282
return this.model.groups.length === 1 || !this.model.isDraggable;
8383
}
84+
85+
/**
86+
* Gets the control of the specified group model. It adds the startingIndex property to the group model if it does not
87+
* already have it. This ensures that the controls are always linked to the correct group model.
88+
* @param groupModel The group model to get the control for.
89+
* @returns The form control of the specified group model.
90+
*/
91+
getControlOfGroup(groupModel: any) {
92+
if (!groupModel.hasOwnProperty('startingIndex')) {
93+
groupModel.startingIndex = groupModel.index;
94+
}
95+
return this.control.get([groupModel.startingIndex]);
96+
}
8497
}

0 commit comments

Comments
 (0)