Skip to content

Commit

Permalink
settings.logic.updateExpressionsOnDeleting fix #4851 (#4852)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov authored Nov 7, 2023
1 parent cd91089 commit 23606d2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/survey-creator-core/src/creator-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,7 @@ export class CreatorBase extends Base
this.deleteObjectCore(obj);
}
protected updateConditionsOnRemove(obj: any) {
if(!settings.logic.updateExpressionsOnDeleting.question) return;
var objType = SurveyHelper.getObjectType(obj);
var questions;
if (objType == ObjType.Question) {
Expand Down
6 changes: 6 additions & 0 deletions packages/survey-creator-core/src/creator-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export var settings = {
questionName: true,
columnName: true,
choiceValue: true
},
/**
* Set these properties to false if you don't want to update expressions on deleting question
*/
updateExpressionsOnDeleting: {
question: true
}
},
/**
Expand Down
23 changes: 23 additions & 0 deletions packages/survey-creator-core/tests/tabs/logic.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2811,6 +2811,29 @@ test("Use settings to disable updating expressions on changing name and choices"
expect(creator.survey.getQuestionByName("q4").visibleIf).toEqual("{q2} = ['item1']");
expect(matrix.columns[1].visibleIf).toEqual("{row.col1} = 1");
});
test("Delete the question && settings.logic.updateExpressionsOnDeleting", () => {
const creator = new CreatorTester();
creator.JSON = {
elements: [
{ type: "text", name: "q1", visibleIf: "{q3} > 2" },
{
type: "text",
name: "q2",
visibleIf: "{q1} = 1 and {q3} < 2 or {q1} = 2"
},
{ type: "text", name: "q3" }
]
};
settings.logic.updateExpressionsOnDeleting.question = false;
const survey = creator.survey;
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
const q3 = survey.getQuestionByName("q3");
creator.deleteElement(q3);
expect(q1.visibleIf).toEqual("{q3} > 2");
expect(q2.visibleIf).toEqual("{q1} = 1 and {q3} < 2 or {q1} = 2");
settings.logic.updateExpressionsOnDeleting.question = true;
});
test("Update expression on changing column name", (): any => {
const creator = new CreatorTester();
creator.JSON = {
Expand Down

0 comments on commit 23606d2

Please sign in to comment.