Skip to content

Commit 7f5c128

Browse files
committed
SurveyLogic: Delete completedHtmlOnCondition item instead of removing expression only, fix #6657 (#6658)
1 parent dfb1db0 commit 7f5c128

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

packages/survey-creator-core/src/components/tabs/logic-items.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,22 @@ export class SurveyLogicAction {
4444
public apply(expression: string, isRenaming: boolean = false): void {
4545
if (!!this.element && !!this.logicType) {
4646
this.element[this.logicType.propertyName] = expression;
47-
if (
48-
!expression &&
49-
Serializer.isDescendantOf(this.element.getType(), "surveytrigger")
50-
) {
51-
var index = this.survey.triggers.indexOf(<SurveyTrigger>this.element);
52-
if (index > -1) {
53-
this.survey.triggers.splice(index, 1);
47+
if (!expression) {
48+
if(Serializer.isDescendantOf(this.element.getType(), "surveytrigger")) {
49+
this.removeElement(this.survey.triggers, this.element);
50+
}
51+
if(Serializer.isDescendantOf(this.element.getType(), "htmlconditionitem")) {
52+
this.removeElement(this.survey.completedHtmlOnCondition, this.element);
5453
}
5554
}
5655
}
5756
}
57+
private removeElement(items: Array<any>, element: any): void {
58+
var index = items.indexOf(this.element);
59+
if (index > -1) {
60+
items.splice(index, 1);
61+
}
62+
}
5863
public renameQuestion(oldName: string, newName: string): void {
5964
if (!this.element) return;
6065
var names = this.questionNames;

packages/survey-creator-core/tests/tabs/logic.tests.ts

+16
Original file line numberDiff line numberDiff line change
@@ -3628,3 +3628,19 @@ test("Limit the number of trigger types, #6031", () => {
36283628

36293629
expect(logic.logicTypes.length > 4).toBeTruthy();
36303630
});
3631+
test("SurveyLogic: Delete completedHtmlOnCondition item instead of removing expression only, Bug#6657", () => {
3632+
var survey = new SurveyModel({
3633+
elements: [
3634+
{ type: "text", name: "q1" },
3635+
],
3636+
completedHtmlOnCondition: [
3637+
{ expression: "{q1} = 4", html: "Custom html" },
3638+
]
3639+
});
3640+
expect(survey.completedHtmlOnCondition).toHaveLength(1);
3641+
const logic = new SurveyLogicUI(survey);
3642+
expect(logic.items).toHaveLength(1);
3643+
logic.removeItem(logic.items[0]);
3644+
expect(survey.completedHtmlOnCondition).toHaveLength(0);
3645+
});
3646+

0 commit comments

Comments
 (0)