Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The creator.saveSurveyFunc is not raised when an existing Logic rule … #6503

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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