Skip to content

Commit

Permalink
#6635 The removeSubItems function doesn't remove corresponding input …
Browse files Browse the repository at this point in the history
…types in a property grid

Fixes #6635
  • Loading branch information
novikov82 committed Feb 26, 2025
1 parent a8e8e95 commit b0462c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/survey-creator-core/src/components/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
const action = this.creator.createIActionBarItemByClass(item, needSeparator, (questionType, json) => { this.convertQuestion(questionType, json, defaultJsons); });
if (this.toolboxItemIsCorresponded(item, !!selectedAction)) {
selectedAction = action;
selectedSubactions = item.items;
}
if (item.items?.length > 0 && this.creator.toolbox.showSubitems) {
const subactions = [];
Expand Down Expand Up @@ -621,12 +620,12 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
cssClasses: listComponentCss,
});
this.updateQuestionTypeOrSubtypeListModel(listModel, true);
if (listModel.actions.length == 0) return null;

const propName = QuestionToolbox.getSubTypePropertyName(this.surveyElement.getType());
if (!listModel.selectedItem && !propName) return null;
const actionData: IAction = {
id: "convertInputType",
visibleIndex: 1,
title: listModel.selectedItem?.title || "SUBTYPE",
title: listModel.selectedItem?.title || editorLocalization.getPropertyValueInEditor(propName, this.surveyElement.getPropertyValue(propName)) || "SUBTYPE",
disableShrink: true,
iconName: "icon-chevron_16x16"
};
Expand All @@ -637,14 +636,13 @@ export class QuestionAdornerViewModel extends SurveyElementAdornerBase {
this.updateQuestionTypeOrSubtypeListModel(listModel, true);
}
});

this.surveyElement.registerFunctionOnPropertiesValueChanged(
["inputType", "rateType"],
[propName],
(newValue) => {
const popup = newAction.popupModel;
const list = popup.contentComponentData.model;
this.updateQuestionTypeOrSubtypeListModel(list, true);
newAction.title = list.selectedItem?.title || newValue;
newAction.title = list.selectedItem?.title || editorLocalization.getPropertyValueInEditor(propName, newValue) || "SUBTYPE";
},
"inputTypeAdorner"
);
Expand Down
34 changes: 34 additions & 0 deletions packages/survey-creator-core/tests/question-adorner.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,40 @@ test("Check question adorners popups display mode", (): any => {
expect(convertToAction.popupModel.displayMode).toBe("overlay");
});

test("Check question converter with removed subitems", (): any => {
surveySettings.animationEnabled = false;
const creator = new CreatorTester();

// create subitems from new items (the same type, different json)

const ratingItem = creator.toolbox.getItemByName("rating");

// Remove Default Subitems
ratingItem.removeSubitem("stars");

ratingItem.title = "Rating Scale";

creator.JSON = {
elements: [
{ type: "rating", name: "q1", rateType: "stars" },
]
};
const question = creator.survey.getQuestionByName("q1");
let questionAdorner = new QuestionAdornerViewModel(
creator,
question,
<any>undefined
);
let convertInputTypeAction = questionAdorner.actionContainer.getActionById("convertInputType");
expect(convertInputTypeAction.title).toBe("Stars");
question.rateType = "smileys";
expect(convertInputTypeAction.title).toBe("Smileys");
question.rateType = "stars";
expect(convertInputTypeAction.title).toBe("Stars");

surveySettings.animationEnabled = true;
});

test("Check question adorners icons", (): any => {
const creator = new CreatorTester();
creator.JSON = {
Expand Down

0 comments on commit b0462c0

Please sign in to comment.