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

Allow to use copy trigger without expression fix #7030 #7031

Merged
merged 1 commit into from
Sep 28, 2023
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
23 changes: 20 additions & 3 deletions src/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,14 @@ export class Trigger extends Base {
if (!this.isCheckRequired(keys)) return;
if (!!this.conditionRunner) {
this.perform(values, properties);
} else {
if(this.canSuccessOnEmptyExpression()) {
this.triggerResult(true, values, properties);
}
}
}
public check(value: any) {
protected canSuccessOnEmptyExpression(): boolean { return false; }
public check(value: any): void {
var triggerResult = Trigger.operators[this.operator](value, this.value);
if (triggerResult) {
this.onSuccess({}, null);
Expand Down Expand Up @@ -174,8 +179,12 @@ export class Trigger extends Base {
private isCheckRequired(keys: any): boolean {
if (!keys) return false;
this.createConditionRunner();
if (this.conditionRunner.hasFunction() === true) return true;
return new ProcessValue().isAnyKeyChanged(keys, this.conditionRunner.getVariables());
if (this.conditionRunner && this.conditionRunner.hasFunction() === true) return true;
return new ProcessValue().isAnyKeyChanged(keys, this.getUsedVariables());
}
protected getUsedVariables(): string[] {
if(!this.conditionRunner) return [];
return this.conditionRunner.getVariables();
}
private createConditionRunner() {
if (!!this.conditionRunner) return;
Expand Down Expand Up @@ -431,6 +440,14 @@ export class SurveyTriggerCopyValue extends SurveyTrigger {
if (!this.setToName || !this.owner) return;
this.owner.copyTriggerValue(this.setToName, this.fromName, this.copyDisplayValue);
}
protected canSuccessOnEmptyExpression(): boolean { return true; }
protected getUsedVariables(): string[] {
const res = super.getUsedVariables();
if(res.length === 0 && !!this.fromName) {
res.push(this.fromName);
}
return res;
}
}

Serializer.addClass("trigger", [
Expand Down
25 changes: 25 additions & 0 deletions tests/surveytriggertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,31 @@ QUnit.test("copyvalue from checkbox", function(assert) {
q1.value = [1, 2];
assert.deepEqual(q2.value, "Item1, Item2", "Copy value correctly");
});
QUnit.test("copyvalue without expression, bug#7030", function(assert) {
const survey = new SurveyModel({
elements: [
{ type: "text", name: "q1" },
{ type: "text", name: "q2" },
{ type: "text", name: "q3" }

],
"triggers": [
{
"type": "copyvalue",
"fromName": "q1",
"setToName": "q2"
}
],
});
const q1 = survey.getQuestionByName("q1");
const q2 = survey.getQuestionByName("q2");
const q3 = survey.getQuestionByName("q3");
q1.value = "A";
assert.equal(q2.value, "A", "Copy value correctly");
q2.value = "B";
q3.value = "C";
assert.equal(q2.value, "B", "Do not copy value");
});

QUnit.test("Execute trigger on complete", function(assert) {
class TriggerExprssionTester extends SurveyTriggerRunExpression {
Expand Down
Loading