Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6694 The subitem dropdown throws an exception on selecting an item when the creator.toolbox.showSubitems option is disabled #6712

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/survey-creator-core/src/components/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
element.closest(".svc-question__drag-area") && !element.closest(".svc-question__top-actions") ||
element.closest(".sd-element__header") && !element.closest(".svc-string-editor");
}

protected updateQuestionTypeOrSubtypeListModel(listModel: ListModel, subtypeOnly: boolean) {
const availableItems = this.getConvertToTypes();
const defaultJsons = this.buildDefaultJsonMap(availableItems);
Expand All @@ -549,25 +550,32 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
let selectedAction: IAction;
let selectedSubaction: IAction = undefined;
let selectedSubactions = undefined;

const toolboxItemToAction = (item, needSeparator = false) => {
return this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
};

availableItems.forEach((item: QuestionToolboxItem) => {
const needSeparator = lastItem && item.category != lastItem.category;
const action = this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
const action = toolboxItemToAction(item, needSeparator);
if (this.toolboxItemIsCorresponded(item, !!selectedAction)) {
selectedAction = action;
selectedSubactions = item.items;
if (item.items) {
selectedSubactions = item.items.map(subitem => toolboxItemToAction(subitem));
}
}
if (item.items?.length > 0 && this.creator.toolbox.showSubitems) {
const subactions = [];
let selectedSubactionLocal: IAction = undefined;
let allChildsAreCompatibleToParent = false;
item.items.forEach(subitem => {
const subaction = this.creator.createIActionBarItemByClass(subitem, false, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
const subaction = toolboxItemToAction(subitem,);
if (this.toolboxItemIsCorresponded(subitem, !!selectedAction)) selectedSubactionLocal = subitem;
if (this.jsonsAreCompatible(item.json, subitem.json)) allChildsAreCompatibleToParent = true;
subactions.push(subaction);
});
if (!allChildsAreCompatibleToParent && subactions.length > 0) {
const defaultSubaction = this.creator.createIActionBarItemByClass(item, false, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
const defaultSubaction = toolboxItemToAction(item);
defaultSubaction.id = action.id + "-default";
defaultSubaction.iconName = undefined;
defaultSubaction.markerIconName = undefined;
Expand Down
7 changes: 7 additions & 0 deletions packages/survey-creator-core/tests/question-adorner.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ test("Check question converter no subitems", (): any => {
const list = popup.contentComponentData.model;
expect((list.getActionById("text").items || []).length).toBe(0);

const convertInputType = questionAdorner.actionContainer.getActionById("convertInputType");
const popupInputType = convertInputType.popupModel;
const popupInputTypeViewModel = new PopupDropdownViewModel(popupInputType); // need for popupModel.onShow
popupInputType.show();
const listInputType = popupInputType.contentComponentData.model;
expect(listInputType.actions.every(a => !(a instanceof QuestionToolboxItem))).toBeTruthy();

surveySettings.animationEnabled = true;
});

Expand Down