Skip to content

Commit 6632961

Browse files
authored
#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 5628d86 commit 6632961

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
@@ -541,6 +541,7 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
541541
element.closest(".svc-question__drag-area") && !element.closest(".svc-question__top-actions") ||
542542
element.closest(".sd-element__header") && !element.closest(".svc-string-editor");
543543
}
544+
544545
protected updateQuestionTypeOrSubtypeListModel(listModel: ListModel, subtypeOnly: boolean) {
545546
const availableItems = this.getConvertToTypes();
546547
const defaultJsons = this.buildDefaultJsonMap(availableItems);
@@ -549,25 +550,32 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
549550
let selectedAction: IAction;
550551
let selectedSubaction: IAction = undefined;
551552
let selectedSubactions = undefined;
553+
554+
const toolboxItemToAction = (item, needSeparator = false) => {
555+
return this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
556+
};
557+
552558
availableItems.forEach((item: QuestionToolboxItem) => {
553559
const needSeparator = lastItem && item.category != lastItem.category;
554-
const action = this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
560+
const action = toolboxItemToAction(item, needSeparator);
555561
if (this.toolboxItemIsCorresponded(item, !!selectedAction)) {
556562
selectedAction = action;
557-
selectedSubactions = item.items;
563+
if (item.items) {
564+
selectedSubactions = item.items.map(subitem => toolboxItemToAction(subitem));
565+
}
558566
}
559567
if (item.items?.length > 0 && this.creator.toolbox.showSubitems) {
560568
const subactions = [];
561569
let selectedSubactionLocal: IAction = undefined;
562570
let allChildsAreCompatibleToParent = false;
563571
item.items.forEach(subitem => {
564-
const subaction = this.creator.createIActionBarItemByClass(subitem, false, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
572+
const subaction = toolboxItemToAction(subitem,);
565573
if (this.toolboxItemIsCorresponded(subitem, !!selectedAction)) selectedSubactionLocal = subitem;
566574
if (this.jsonsAreCompatible(item.json, subitem.json)) allChildsAreCompatibleToParent = true;
567575
subactions.push(subaction);
568576
});
569577
if (!allChildsAreCompatibleToParent && subactions.length > 0) {
570-
const defaultSubaction = this.creator.createIActionBarItemByClass(item, false, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
578+
const defaultSubaction = toolboxItemToAction(item);
571579
defaultSubaction.id = action.id + "-default";
572580
defaultSubaction.iconName = undefined;
573581
defaultSubaction.markerIconName = undefined;

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

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

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

0 commit comments

Comments
 (0)