From d3d24e01a7ff42213bc342ee214adf99141b878d Mon Sep 17 00:00:00 2001 From: rhenck <richard.henck@iqb.hu-berlin.de> Date: Tue, 9 Nov 2021 13:09:32 +0100 Subject: [PATCH] Use readOnly setting for DnD element The drop listener simply does nothing when this is set. This way it is still possbiel to drag item but dropping them has no effect. --- .../compound-elements/drop-list.component.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/projects/common/element-components/compound-elements/drop-list.component.ts b/projects/common/element-components/compound-elements/drop-list.component.ts index 01f33a58f..62c2968d3 100644 --- a/projects/common/element-components/compound-elements/drop-list.component.ts +++ b/projects/common/element-components/compound-elements/drop-list.component.ts @@ -48,18 +48,20 @@ export class DropListComponent extends FormElementComponent { elementModel!: DropListElement; drop(event: CdkDragDrop<DropListComponent>): void { - if (event.previousContainer === event.container) { - moveItemInArray(event.container.data.elementModel.options, event.previousIndex, event.currentIndex); - } else { - transferArrayItem( - event.previousContainer.data.elementModel.options, - event.container.data.elementModel.options, - event.previousIndex, - event.currentIndex - ); - event.previousContainer.data.elementFormControl.setValue(event.previousContainer.data.elementModel.options); + if (!this.elementModel.readOnly) { + if (event.previousContainer === event.container) { + moveItemInArray(event.container.data.elementModel.options, event.previousIndex, event.currentIndex); + } else { + transferArrayItem( + event.previousContainer.data.elementModel.options, + event.container.data.elementModel.options, + event.previousIndex, + event.currentIndex + ); + event.previousContainer.data.elementFormControl.setValue(event.previousContainer.data.elementModel.options); + } + this.elementFormControl.setValue(event.container.data.elementModel.options); } - this.elementFormControl.setValue(event.container.data.elementModel.options); } onlyOneItemPredicate(drag: CdkDrag, drop: CdkDropList): boolean { -- GitLab