diff --git a/src/dragdrophelper.ts b/src/dragdrophelper.ts index d868e0a501..0f9c3a6cc8 100644 --- a/src/dragdrophelper.ts +++ b/src/dragdrophelper.ts @@ -1,7 +1,10 @@ import * as ko from "knockout"; import * as Survey from "survey-knockout"; import { SurveyHelper } from "./surveyHelper"; -ko.options.useOnlyNativeEvents = true; + +if (!!ko.options) { + ko.options.useOnlyNativeEvents = true; +} export class DragDropTargetElement { public moveToParent: any; diff --git a/src/propertyEditors/propertyTriggersEditor.ts b/src/propertyEditors/propertyTriggersEditor.ts index 7eca4c7236..7d414b819d 100644 --- a/src/propertyEditors/propertyTriggersEditor.ts +++ b/src/propertyEditors/propertyTriggersEditor.ts @@ -175,8 +175,9 @@ export class SurveyPropertyTrigger { expressionProperty ); this.conditionEditor.showHelpText = false; - //TODO replace with property and function - this.trigger["expression"] = this.trigger["buildExpression"](); + if (!this.trigger.expression) { + this.trigger.expression = this.trigger.buildExpression(); + } this.conditionEditor.object = this.trigger; } var self = this; @@ -184,12 +185,15 @@ export class SurveyPropertyTrigger { return self.koOperator() != "empty" && self.koOperator() != "notempty"; }); this.koIsValid = ko.computed(() => { + if (!!this.conditionEditor) { + var text = self.conditionEditor.koTextValue(); + return !!text; + } if (self.koName() && (!self.koRequireValue() || self.koValue())) return true; return false; }); this.koText = ko.computed(() => { - if (!!self.conditionEditor) return self.conditionEditor.koTextValue(); self.koName(); self.koOperator(); self.koValue(); @@ -213,6 +217,11 @@ export class SurveyPropertyTrigger { private getText(): string { if (!this.koIsValid()) return editorLocalization.getString("pe.triggerNotSet"); + if (!!this.conditionEditor) { + var res = this.conditionEditor.koTextValue(); + if (!res) return ""; + return editorLocalization.getString("pe.triggerRunIf") + ": " + res; + } return ( editorLocalization.getString("pe.triggerRunIf") + " '" + diff --git a/tests/propertyEditors/propertyEditorsTests.ts b/tests/propertyEditors/propertyEditorsTests.ts index d55d433cbb..0d6baae532 100644 --- a/tests/propertyEditors/propertyEditorsTests.ts +++ b/tests/propertyEditors/propertyEditorsTests.ts @@ -889,9 +889,11 @@ QUnit.test("Triggers property editor", function(assert) { "There are one trigger initially" ); var koTrigger = propEditor.koSelected(); - assert.equal(koTrigger.koName(), "question1", "Name set correctly"); - assert.equal(koTrigger.koOperator(), "notequal", "operator set correctly"); - assert.equal(koTrigger.koValue(), "val1", "value set correctly"); + assert.equal( + koTrigger.conditionEditor.koTextValue(), + "{question1} notequal 'val1'", + "expression set correctly" + ); assert.deepEqual( koTrigger.questions.koChoosen(), ["question2"], @@ -901,17 +903,13 @@ QUnit.test("Triggers property editor", function(assert) { propEditor.onAddClick({ value: "visibletrigger" }); assert.equal(propEditor.koItems().length, 2, "There are two triggers now"); koTrigger = propEditor.koSelected(); - assert.equal(koTrigger.koOperator(), "equal", "default operator is equal"); + assert.equal(koTrigger.koIsValid(), false, "the trigger is not valid"); - koTrigger.koName("question2"); - assert.equal(koTrigger.koIsValid(), false, "the trigger is still not valid"); - assert.equal(koTrigger.koRequireValue(), true, "value should be set"); - koTrigger.koOperator("notempty"); + koTrigger.conditionEditor.koTextValue("{question2} notempty"); assert.equal(koTrigger.koIsValid(), true, "the trigger is valid"); - assert.equal(koTrigger.koRequireValue(), false, "value should not be set"); assert.equal( koTrigger.koText(), - "Run if 'question2' is not empty", + "Run if: {question2} notempty", "text for valid trigger" ); @@ -919,13 +917,11 @@ QUnit.test("Triggers property editor", function(assert) { koTrigger.questions.koChoosen.push("question3"); koTrigger.koValue(1); trigger = koTrigger.createTrigger(); - assert.equal(trigger.name, "question2", "create trigger correctly: name"); assert.equal( - trigger.operator, - "notempty", - "create trigger correctly: operator" + koTrigger.conditionEditor.koTextValue(), + "{question2} notempty", + "set condition correctly" ); - assert.equal(trigger.value, 1, "create trigger correctly: value"); assert.deepEqual(trigger.pages, ["page2"], "create trigger correctly: pages"); assert.deepEqual( trigger.questions,