Skip to content

Commit 5522423

Browse files
authored
#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 0ebc8bd commit 5522423

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
@@ -565,7 +565,6 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
565565
const action = this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
566566
if (this.toolboxItemIsCorresponded(item, !!selectedAction)) {
567567
selectedAction = action;
568-
selectedSubactions = item.items;
569568
}
570569
if (item.items?.length > 0 && this.creator.toolbox.showSubitems) {
571570
const subactions = [];
@@ -591,8 +590,8 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
591590
if (selectedSubactionLocal) {
592591
selectedAction = action;
593592
selectedSubaction = selectedSubactionLocal;
594-
selectedSubactions = subactions;
595593
}
594+
selectedSubactions = subactions;
596595
}
597596
lastItem = item;
598597
newItems.push(action);
@@ -621,12 +620,12 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
621620
cssClasses: listComponentCss,
622621
});
623622
this.updateQuestionTypeOrSubtypeListModel(listModel, true);
624-
if (listModel.actions.length == 0) return null;
625-
623+
const propName = QuestionToolbox.getSubTypePropertyName(this.surveyElement.getType());
624+
if (!listModel.selectedItem && !propName) return null;
626625
const actionData: IAction = {
627626
id: "convertInputType",
628627
visibleIndex: 1,
629-
title: listModel.selectedItem?.title || "SUBTYPE",
628+
title: listModel.selectedItem?.title || editorLocalization.getPropertyValueInEditor(propName, this.surveyElement.getPropertyValue(propName)) || "SUBTYPE",
630629
disableShrink: true,
631630
iconName: "icon-chevron_16x16"
632631
};
@@ -637,14 +636,13 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
637636
this.updateQuestionTypeOrSubtypeListModel(listModel, true);
638637
}
639638
});
640-
641639
this.surveyElement.registerFunctionOnPropertiesValueChanged(
642-
["inputType", "rateType"],
643-
() => {
640+
[propName],
641+
(newValue) => {
644642
const popup = newAction.popupModel;
645643
const list = popup.contentComponentData.model;
646644
this.updateQuestionTypeOrSubtypeListModel(list, true);
647-
newAction.title = list.selectedItem.title;
645+
newAction.title = list.selectedItem?.title || editorLocalization.getPropertyValueInEditor(propName, newValue) || "SUBTYPE";
648646
},
649647
"inputTypeAdorner"
650648
);

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

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

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

0 commit comments

Comments
 (0)