Skip to content

Commit

Permalink
Merge pull request #3679 from 4Science/task/main/DURACOM-297
Browse files Browse the repository at this point in the history
#3678, #3217 - Fix ordering and changing values of repeatable inputs in submission form
  • Loading branch information
tdonohue authored Dec 19, 2024
2 parents 225a2b6 + 1c92721 commit 6ac9229
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 @@ -114,4 +114,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;
}
return this.control.get([groupModel.startingIndex]);
}
}

0 comments on commit 6ac9229

Please sign in to comment.