Skip to content

Commit 5828b8f

Browse files
committed
#6694 The subitem dropdown throws an exception on selecting an item when the creator.toolbox.showSubitems option is disabled (#6712)
* #6694 The subitem dropdown throws an exception on selecting an item when the `creator.toolbox.showSubitems` option is disabled Fixes #6694 * #6694 - fixed unit tests
1 parent 2e1bb35 commit 5828b8f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

packages/survey-creator-core/src/components/question.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
557557
element.closest(".svc-question__drag-area") && !element.closest(".svc-question__top-actions") ||
558558
element.closest(".sd-element__header") && !element.closest(".svc-string-editor");
559559
}
560+
560561
protected updateQuestionTypeOrSubtypeListModel(listModel: ListModel, subtypeOnly: boolean) {
561562
const availableItems = this.getConvertToTypes();
562563
const defaultJsons = this.buildDefaultJsonMap(availableItems);
@@ -565,25 +566,32 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
565566
let selectedAction: IAction;
566567
let selectedSubaction: IAction = undefined;
567568
let selectedSubactions = undefined;
569+
570+
const toolboxItemToAction = (item, needSeparator = false) => {
571+
return this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
572+
};
573+
568574
availableItems.forEach((item: QuestionToolboxItem) => {
569575
const needSeparator = lastItem && item.category != lastItem.category;
570-
const action = this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
576+
const action = toolboxItemToAction(item, needSeparator);
571577
if (this.toolboxItemIsCorresponded(item, !!selectedAction)) {
572578
selectedAction = action;
573-
selectedSubactions = item.items;
579+
if (item.items) {
580+
selectedSubactions = item.items.map(subitem => toolboxItemToAction(subitem));
581+
}
574582
}
575583
if (item.items?.length > 0 && this.creator.toolbox.showSubitems) {
576584
const subactions = [];
577585
let selectedSubactionLocal: IAction = undefined;
578586
let allChildsAreCompatibleToParent = false;
579587
item.items.forEach(subitem => {
580-
const subaction = this.creator.createIActionBarItemByClass(subitem, false, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
588+
const subaction = toolboxItemToAction(subitem,);
581589
if (this.toolboxItemIsCorresponded(subitem, !!selectedAction)) selectedSubactionLocal = subitem;
582590
if (this.jsonsAreCompatible(item.json, subitem.json)) allChildsAreCompatibleToParent = true;
583591
subactions.push(subaction);
584592
});
585593
if (!allChildsAreCompatibleToParent && subactions.length > 0) {
586-
const defaultSubaction = this.creator.createIActionBarItemByClass(item, false, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
594+
const defaultSubaction = toolboxItemToAction(item);
587595
defaultSubaction.id = action.id + "-default";
588596
defaultSubaction.iconName = undefined;
589597
defaultSubaction.markerIconName = undefined;

packages/survey-creator-core/tests/question-adorner.tests.ts

+7
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ test("Check question converter no subitems", (): any => {
335335
const list = popup.contentComponentData.model;
336336
expect((list.getActionById("text").items || []).length).toBe(0);
337337

338+
const convertInputType = questionAdorner.actionContainer.getActionById("convertInputType");
339+
const popupInputType = convertInputType.popupModel;
340+
const popupInputTypeViewModel = new PopupDropdownViewModel(popupInputType); // need for popupModel.onShow
341+
popupInputType.show();
342+
const listInputType = popupInputType.contentComponentData.model;
343+
expect(listInputType.actions.every(a => !(a instanceof QuestionToolboxItem))).toBeTruthy();
344+
338345
surveySettings.animationEnabled = true;
339346
});
340347

0 commit comments

Comments
 (0)