Skip to content

Commit 0648fdb

Browse files
committed
#6635 The removeSubItems function doesn't remove corresponding input types in a property grid (#6651)
* #6635 The removeSubItems function doesn't remove corresponding input types in a property grid Fixes #6635 * #6635 The removeSubItems function doesn't remove corresponding input types in a property grid Fixes #6635
1 parent 0faa138 commit 0648fdb

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

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

+7-9
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
570570
const action = this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
571571
if (this.toolboxItemIsCorresponded(item, !!selectedAction)) {
572572
selectedAction = action;
573-
selectedSubactions = item.items;
574573
}
575574
if (item.items?.length > 0 && this.creator.toolbox.showSubitems) {
576575
const subactions = [];
@@ -596,8 +595,8 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
596595
if (selectedSubactionLocal) {
597596
selectedAction = action;
598597
selectedSubaction = selectedSubactionLocal;
599-
selectedSubactions = subactions;
600598
}
599+
selectedSubactions = subactions;
601600
}
602601
lastItem = item;
603602
newItems.push(action);
@@ -626,12 +625,12 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
626625
cssClasses: listComponentCss,
627626
});
628627
this.updateQuestionTypeOrSubtypeListModel(listModel, true);
629-
if (listModel.actions.length == 0) return null;
630-
628+
const propName = QuestionToolbox.getSubTypePropertyName(this.surveyElement.getType());
629+
if (!listModel.selectedItem && !propName) return null;
631630
const actionData: IAction = {
632631
id: "convertInputType",
633632
visibleIndex: 1,
634-
title: listModel.selectedItem?.title || "SUBTYPE",
633+
title: listModel.selectedItem?.title || editorLocalization.getPropertyValueInEditor(propName, this.surveyElement.getPropertyValue(propName)) || "SUBTYPE",
635634
disableShrink: true,
636635
iconName: "icon-chevron_16x16"
637636
};
@@ -642,14 +641,13 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
642641
this.updateQuestionTypeOrSubtypeListModel(listModel, true);
643642
}
644643
});
645-
646644
this.surveyElement.registerFunctionOnPropertiesValueChanged(
647-
["inputType", "rateType"],
648-
() => {
645+
[propName],
646+
(newValue) => {
649647
const popup = newAction.popupModel;
650648
const list = popup.contentComponentData.model;
651649
this.updateQuestionTypeOrSubtypeListModel(list, true);
652-
newAction.title = list.selectedItem.title;
650+
newAction.title = list.selectedItem?.title || editorLocalization.getPropertyValueInEditor(propName, newValue) || "SUBTYPE";
653651
},
654652
"inputTypeAdorner"
655653
);

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

+34
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,40 @@ test("Check question adorners popups display mode", (): any => {
6666
expect(convertToAction.popupModel.displayMode).toBe("overlay");
6767
});
6868

69+
test("Check question converter with removed subitems", (): any => {
70+
surveySettings.animationEnabled = false;
71+
const creator = new CreatorTester();
72+
73+
// create subitems from new items (the same type, different json)
74+
75+
const ratingItem = creator.toolbox.getItemByName("rating");
76+
77+
// Remove Default Subitems
78+
ratingItem.removeSubitem("stars");
79+
80+
ratingItem.title = "Rating Scale";
81+
82+
creator.JSON = {
83+
elements: [
84+
{ type: "rating", name: "q1", rateType: "stars" },
85+
]
86+
};
87+
const question = creator.survey.getQuestionByName("q1");
88+
let questionAdorner = new QuestionAdornerViewModel(
89+
creator,
90+
question,
91+
<any>undefined
92+
);
93+
let convertInputTypeAction = questionAdorner.actionContainer.getActionById("convertInputType");
94+
expect(convertInputTypeAction.title).toBe("Stars");
95+
question.rateType = "smileys";
96+
expect(convertInputTypeAction.title).toBe("Smileys");
97+
question.rateType = "stars";
98+
expect(convertInputTypeAction.title).toBe("Stars");
99+
100+
surveySettings.animationEnabled = true;
101+
});
102+
69103
test("Check question adorners icons", (): any => {
70104
const creator = new CreatorTester();
71105
creator.JSON = {

0 commit comments

Comments
 (0)