Skip to content

Commit 11ebf90

Browse files
author
tsv2013
committed
Introduce an API to restrict questions and panels from being added or dropped into other container elements (e.g., other panels or dynamic panels)
Fixes #6646
1 parent abb057c commit 11ebf90

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/survey-creator-core/src/creator-base.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4154,20 +4154,28 @@ export class SurveyCreatorModel extends Base
41544154
public get addNewQuestionText() {
41554155
return this.getAddNewQuestionText();
41564156
}
4157+
public isAllowedNestingLevel(element: SurveyElement, childNesting = 0): boolean {
4158+
if (!element) return true;
4159+
return this.maxNestingLevel < 0 || this.maxNestingLevel >= childNesting + SurveyHelper.getElementParentContainers(element).length;
4160+
}
4161+
public isAllowedNestedPanels(element: SurveyElement, childNesting = 0): boolean {
4162+
if (!element) return true;
4163+
return this.maxNestedPanels < 0 || this.maxNestedPanels >= childNesting + SurveyHelper.getElementDeepLength(element);
4164+
}
41574165
public getAvailableToolboxItems(element?: SurveyElement, isAddNew: boolean = true): Array<QuestionToolboxItem> {
41584166
const res: Array<QuestionToolboxItem> = [];
41594167
this.toolbox.items.forEach((item) => { if (!item.showInToolboxOnly) res.push(item); });
41604168

41614169
if (!element) return res;
41624170
if (!isAddNew && (element.isPanel || SurveyHelper.isPanelDynamic(element))) return res;
41634171

4164-
if (this.maxNestingLevel >= 0 && this.maxNestingLevel < SurveyHelper.getElementParentContainers(element).length) {
4172+
if (!this.isAllowedNestingLevel(element)) {
41654173
for (let i = res.length - 1; i >= 0; i--) {
41664174
if (res[i].isPanel || Serializer.isDescendantOf(res[i].typeName, "paneldynamic")) {
41674175
res.splice(i, 1);
41684176
}
41694177
}
4170-
} else if (this.maxNestedPanels >= 0 && this.maxNestedPanels < SurveyHelper.getElementDeepLength(element)) {
4178+
} else if (!this.isAllowedNestedPanels(element)) {
41714179
for (let i = res.length - 1; i >= 0; i--) {
41724180
if (res[i].isPanel) {
41734181
res.splice(i, 1);

0 commit comments

Comments
 (0)