Skip to content

Commit

Permalink
The creator.saveSurveyFunc is not raised when an existing Logic rule …
Browse files Browse the repository at this point in the history
…is updated fix #6502 (#6503)
  • Loading branch information
andrewtelnov authored Feb 3, 2025
1 parent 3b3e9cc commit a96f173
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,24 @@ export class LogicActionTriggerModel extends LogicActionModelBase {
if (!createNewAction) {
const el = this.initialLogicAction.element;
const srcJson = this.panelObj.toJSON();
const destJson = el.toJSON();
const srcKeys = Object.keys(srcJson);
const destKeys = Object.keys(el.toJSON());
const destKeys = Object.keys(destJson);
const propsToDelete = [];
for(let i = 0; i < destKeys.length; i ++) {
const key = destKeys[i];
const propsToSet = [];
destKeys.forEach(key => {
if(srcKeys.indexOf(key) < 0) {
propsToDelete.push(key);
}
}
el.fromJSON(srcJson);
});
srcKeys.forEach(key => {
if(!Helpers.isTwoValueEquals(srcJson[key], destJson[key])) {
propsToSet.push(key);
}
});
propsToDelete.forEach(prop => el.resetPropertyValue(prop));
propsToSet.forEach(prop => el[prop] = srcJson[prop]);
this.currentLogicAction = this.initialLogicAction;
for(let i = 0; i < propsToDelete.length; i ++) {
el[propsToDelete[i]] = undefined;
}
return false;
}
this.currentLogicAction = new SurveyLogicAction(this.logicType, this.panelObj, survey);
Expand Down
40 changes: 40 additions & 0 deletions packages/survey-creator-core/tests/tabs/logic.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3266,6 +3266,46 @@ test("Test questions css in an action panel", () => {
checkFunc(3, "completedHtmlOnCondition", "html", false);
});

test("Run modified on changing runExpression", () => {
const survey = new SurveyModel({
elements: [
{ type: "text", name: "q1" },
{ type: "text", name: "q2" }
],
triggers: [
{
type: "runexpression",
expression: "{q1} = 3",
runExpression: "{q1} + 3"
}
]
});
const logic = new SurveyLogic(survey);
expect(logic.items).toHaveLength(1);
const editor = new LogicItemEditor(logic.items[0]);
expect(editor.panels).toHaveLength(1);
expect(editor.panels[0].getQuestionByName("elementSelector").visible).toBeFalsy();
const panelTrigger = <PanelModel>(editor.panels[0].getElementByName("triggerEditorPanel"));
expect(panelTrigger).toBeTruthy();
expect(panelTrigger.visible).toBeTruthy();
const runExpressionQuestion = panelTrigger.getQuestionByName("runExpression");
expect(runExpressionQuestion.value).toEqual("{q1} + 3");
const changes = new Array<any>();
survey.onPropertyValueChangedCallback = (
name: string,
oldValue: any,
newValue: any
) => {
changes.push({ name: name, value: newValue });
};
runExpressionQuestion.value = "{q1} + 4";
expect(changes).toHaveLength(0);
editor.apply();
expect(changes).toHaveLength(1);
expect(changes[0].name).toEqual("runExpression");
expect(changes[0].value).toEqual("{q1} + 4");
});

test("Custom trigger in logic", () => {
Serializer.addClass(
"incrementcountertrigger",
Expand Down

0 comments on commit a96f173

Please sign in to comment.