Skip to content

Commit

Permalink
Fix the build
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jul 3, 2018
1 parent 95c84f4 commit 6079371
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/dragdrophelper.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
15 changes: 12 additions & 3 deletions src/propertyEditors/propertyTriggersEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,25 @@ 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;
this.koRequireValue = ko.computed(() => {
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();
Expand All @@ -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") +
" '" +
Expand Down
26 changes: 11 additions & 15 deletions tests/propertyEditors/propertyEditorsTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,11 @@ QUnit.test("Triggers property editor", function(assert) {
"There are one trigger initially"
);
var koTrigger = <SurveyPropertyVisibleTrigger>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"],
Expand All @@ -901,31 +903,25 @@ QUnit.test("Triggers property editor", function(assert) {
propEditor.onAddClick({ value: "visibletrigger" });
assert.equal(propEditor.koItems().length, 2, "There are two triggers now");
koTrigger = <SurveyPropertyVisibleTrigger>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"
);

koTrigger.pages.koChoosen.push("page2");
koTrigger.questions.koChoosen.push("question3");
koTrigger.koValue(1);
trigger = <Survey.SurveyTriggerVisible>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,
Expand Down

0 comments on commit 6079371

Please sign in to comment.