Skip to content

Commit d2ef8a9

Browse files
committed
Fix: Condition Editor could not parse expression with calculated values and unary operator #740
1 parent 15c7400 commit d2ef8a9

File tree

2 files changed

+150
-146
lines changed

2 files changed

+150
-146
lines changed

src/propertyEditors/propertyConditionEditor.ts

+52-52
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Survey from "survey-knockout";
33
import { SurveyPropertyTextEditor } from "./propertyModalEditor";
44
import {
55
SurveyPropertyEditorBase,
6-
ISurveyObjectEditorOptions
6+
ISurveyObjectEditorOptions,
77
} from "./propertyEditorBase";
88
import { SurveyPropertyEditorFactory } from "./propertyEditorFactory";
99
import { EditableObject } from "./editableObject";
@@ -41,14 +41,14 @@ export class ConditionEditorItem {
4141
titleLocation: "hidden",
4242
showOptionsCaption: false,
4343
visible: false,
44-
choices: ["and", "or"]
44+
choices: ["and", "or"],
4545
},
4646
{
4747
name: "questionName",
4848
type: "dropdown",
4949
titleLocation: "hidden",
5050
startWithNewLine: false,
51-
isRequired: true
51+
isRequired: true,
5252
},
5353
{
5454
name: "operator",
@@ -57,9 +57,9 @@ export class ConditionEditorItem {
5757
startWithNewLine: false,
5858
showOptionsCaption: false,
5959
isRequired: true,
60-
enableIf: "{questionName} notempty"
61-
}
62-
]
60+
enableIf: "{questionName} notempty",
61+
},
62+
],
6363
};
6464
this.survey = !!owner.options
6565
? owner.options.createSurvey(json, "conditionEditor")
@@ -180,7 +180,7 @@ export class ConditionEditorItem {
180180
);
181181
if (!json) {
182182
json = {
183-
type: "text"
183+
type: "text",
184184
};
185185
}
186186
json.isRequired = true;
@@ -768,7 +768,7 @@ export class SurveyPropertyConditionEditor extends SurveyPropertyTextEditor
768768
var operand = op.expression;
769769
if (operand == null || operand.getType() != "variable") return false;
770770
var questionName = (<Survey.Variable>operand).variable;
771-
if (!this.getQuestionByName(questionName)) return false;
771+
if (!this.isVariableInSurvey(questionName)) return false;
772772
var item = new ConditionEditorItem(this);
773773
item.questionName = questionName;
774774
item.operator = operator;
@@ -836,119 +836,119 @@ SurveyPropertyEditorFactory.registerTypeForCellEditing("condition", "string");
836836
var operations = [
837837
{
838838
value: "and",
839-
title: "logical 'and' operator"
839+
title: "logical 'and' operator",
840840
},
841841
{
842842
value: "&&",
843-
title: "logical 'and' operator"
843+
title: "logical 'and' operator",
844844
},
845845
{
846846
value: "or",
847-
title: "logical 'or' operator"
847+
title: "logical 'or' operator",
848848
},
849849
{
850850
value: "||",
851-
title: "logical 'or' operator"
851+
title: "logical 'or' operator",
852852
},
853853
{
854854
value: "empty",
855-
title: "returns true if the left operand is empty {questionName} empty"
855+
title: "returns true if the left operand is empty {questionName} empty",
856856
},
857857
{
858858
value: "notempty",
859859
title:
860-
"returns true if the left operand is not empty {questionName} notempty"
860+
"returns true if the left operand is not empty {questionName} notempty",
861861
},
862862
{
863863
value: "=",
864864
title:
865-
"returns true if two values are equal {questionName} = 5, {questionName} == 'abc', {questionName} equal 124"
865+
"returns true if two values are equal {questionName} = 5, {questionName} == 'abc', {questionName} equal 124",
866866
},
867867
{
868868
value: "==",
869869
title:
870-
"returns true if two values are equal {questionName} = 5, {questionName} == 'abc', {questionName} equal 124"
870+
"returns true if two values are equal {questionName} = 5, {questionName} == 'abc', {questionName} equal 124",
871871
},
872872
{
873873
value: "equal",
874874
title:
875-
"returns true if two values are equal {questionName} = 5, {questionName} == 'abc', {questionName} equal 124"
875+
"returns true if two values are equal {questionName} = 5, {questionName} == 'abc', {questionName} equal 124",
876876
},
877877
{
878878
value: "<>",
879879
title:
880-
"returns true if two values are not equal {questionName} <> 5, {questionName} != 'abc', {questionName} notequal 124"
880+
"returns true if two values are not equal {questionName} <> 5, {questionName} != 'abc', {questionName} notequal 124",
881881
},
882882
{
883883
value: "!=",
884884
title:
885-
"returns true if two values are not equal {questionName} <> 5, {questionName} != 'abc', {questionName} notequal 124"
885+
"returns true if two values are not equal {questionName} <> 5, {questionName} != 'abc', {questionName} notequal 124",
886886
},
887887
{
888888
value: "notequal",
889889
title:
890-
"returns true if two values are not equal {questionName} <> 5, {questionName} != 'abc', {questionName} notequal 124"
890+
"returns true if two values are not equal {questionName} <> 5, {questionName} != 'abc', {questionName} notequal 124",
891891
},
892892
{
893893
value: ">",
894894
title:
895-
"returns true if the left operand greater then the second operand {questionName} > 2, {questionName} greater 'a'"
895+
"returns true if the left operand greater then the second operand {questionName} > 2, {questionName} greater 'a'",
896896
},
897897
{
898898
value: "greater",
899899
title:
900-
"returns true if the left operand greater then the second operand {questionName} > 2, {questionName} greater 'a'"
900+
"returns true if the left operand greater then the second operand {questionName} > 2, {questionName} greater 'a'",
901901
},
902902
{
903903
value: "<",
904904
title:
905-
"returns true if the left operand less then the second operand {questionName} < 2, {questionName} less 'a'"
905+
"returns true if the left operand less then the second operand {questionName} < 2, {questionName} less 'a'",
906906
},
907907
{
908908
value: "less",
909909
title:
910-
"returns true if the left operand less then the second operand {questionName} < 2, {questionName} less 'a'"
910+
"returns true if the left operand less then the second operand {questionName} < 2, {questionName} less 'a'",
911911
},
912912
{
913913
value: ">=",
914914
title:
915-
"returns true if the left operand equal or greater then the second operand {questionName} >= 2, {questionName} greaterorequal 'a'"
915+
"returns true if the left operand equal or greater then the second operand {questionName} >= 2, {questionName} greaterorequal 'a'",
916916
},
917917
{
918918
value: "greaterorequal",
919919
title:
920-
"returns true if the left operand equal or greater then the second operand {questionName} >= 2, {questionName} greaterorequal 'a'"
920+
"returns true if the left operand equal or greater then the second operand {questionName} >= 2, {questionName} greaterorequal 'a'",
921921
},
922922
{
923923
value: "<=",
924924
title:
925-
"returns true if the left operand equal or less then the second operand {questionName} <= 2, {questionName} lessorequal 'a'"
925+
"returns true if the left operand equal or less then the second operand {questionName} <= 2, {questionName} lessorequal 'a'",
926926
},
927927
{
928928
value: "lessorequal",
929929
title:
930-
"returns true if the left operand equal or less then the second operand {questionName} <= 2, {questionName} lessorequal 'a'"
930+
"returns true if the left operand equal or less then the second operand {questionName} <= 2, {questionName} lessorequal 'a'",
931931
},
932932
{
933933
value: "contains",
934934
title:
935-
"return true if the left operand is an array and it contains a value of the second operand {questionName} contains 'a'"
935+
"return true if the left operand is an array and it contains a value of the second operand {questionName} contains 'a'",
936936
},
937937
{
938938
value: "notcontains",
939939
title:
940-
"return true if the left operand is an array and it does not contain a value of the second operand"
940+
"return true if the left operand is an array and it does not contain a value of the second operand",
941941
},
942942
{
943943
value: "anyof",
944944
title:
945-
"return true if the left operand is an array and it contains any value of the second array operand"
945+
"return true if the left operand is an array and it contains any value of the second array operand",
946946
},
947947
{
948948
value: "allof",
949949
title:
950-
"return true if the left operand is an array and it contains all values of the second array operand"
951-
}
950+
"return true if the left operand is an array and it contains all values of the second array operand",
951+
},
952952
];
953953

954954
const createAnnotations = (
@@ -966,7 +966,7 @@ const createAnnotations = (
966966
row: condition.match(/\n/g) ? condition.match(/\n/g).length : 0,
967967
column: column,
968968
text: conditionParser.error.code + " (" + column + ")",
969-
type: "error"
969+
type: "error",
970970
};
971971
annotations.push(annotation);
972972
}
@@ -984,7 +984,7 @@ export function doGetCompletions(
984984
var completions = [];
985985
var currentQuestion: Survey.Question = config.question;
986986
var usableQuestions = (config.questions || []).filter(
987-
q => q !== currentQuestion
987+
(q) => q !== currentQuestion
988988
);
989989
if (
990990
!!usableQuestions ||
@@ -996,14 +996,14 @@ export function doGetCompletions(
996996
currentQuestion instanceof Survey.MatrixDropdownColumn
997997
) {
998998
completions = currentQuestion.colOwner["columns"]
999-
.filter(e => e.name !== currentQuestion.name)
1000-
.map(column => {
999+
.filter((e) => e.name !== currentQuestion.name)
1000+
.map((column) => {
10011001
return {
10021002
name: "",
10031003
value: "{row." + column.name + "}",
10041004
some: "",
10051005
meta: column.title,
1006-
identifierRegex: ID_REGEXP
1006+
identifierRegex: ID_REGEXP,
10071007
};
10081008
});
10091009
} else if (
@@ -1012,22 +1012,22 @@ export function doGetCompletions(
10121012
) {
10131013
var panel: Survey.PanelModel = currentQuestion.data.panel;
10141014
completions = panel.elements
1015-
.filter(e => e.name !== currentQuestion.name)
1016-
.map(element => {
1015+
.filter((e) => e.name !== currentQuestion.name)
1016+
.map((element) => {
10171017
return {
10181018
name: "",
10191019
value: "{panel." + element.name + "}",
10201020
some: "",
10211021
meta: element.name,
1022-
identifierRegex: ID_REGEXP
1022+
identifierRegex: ID_REGEXP,
10231023
};
10241024
});
10251025
} else {
10261026
var operationsFiltered = operations.filter(
1027-
op => !prefix || op.value.indexOf(prefix) !== -1
1027+
(op) => !prefix || op.value.indexOf(prefix) !== -1
10281028
);
10291029
var questionsFiltered = usableQuestions.filter(
1030-
op => !prefix || op.name.indexOf(prefix) !== -1
1030+
(op) => !prefix || op.name.indexOf(prefix) !== -1
10311031
);
10321032
if (currentQuestion instanceof Survey.MatrixDropdownColumn) {
10331033
completions.push({
@@ -1037,7 +1037,7 @@ export function doGetCompletions(
10371037
meta: editorLocalization.editorLocalization.getString(
10381038
editorLocalization.defaultStrings.pe.aceEditorRowTitle
10391039
),
1040-
identifierRegex: ID_REGEXP
1040+
identifierRegex: ID_REGEXP,
10411041
});
10421042
} else if (
10431043
!!currentQuestion &&
@@ -1050,30 +1050,30 @@ export function doGetCompletions(
10501050
meta: editorLocalization.editorLocalization.getString(
10511051
editorLocalization.defaultStrings.pe.aceEditorPanelTitle
10521052
),
1053-
identifierRegex: ID_REGEXP
1053+
identifierRegex: ID_REGEXP,
10541054
});
10551055
}
10561056
completions = completions
10571057
.concat(
1058-
questionsFiltered.map(q => {
1058+
questionsFiltered.map((q) => {
10591059
return {
10601060
completer: completer,
10611061
name: "",
10621062
value: "{" + q.name + "}",
10631063
some: "",
10641064
meta: q.title,
1065-
identifierRegex: ID_REGEXP
1065+
identifierRegex: ID_REGEXP,
10661066
};
10671067
})
10681068
)
10691069
.concat(
1070-
operationsFiltered.map(op => {
1070+
operationsFiltered.map((op) => {
10711071
return {
10721072
name: "",
10731073
value: op.value,
10741074
some: "",
10751075
meta: op.title,
1076-
identifierRegex: ID_REGEXP
1076+
identifierRegex: ID_REGEXP,
10771077
};
10781078
})
10791079
);
@@ -1162,12 +1162,12 @@ ko.bindingHandlers.aceEditor = {
11621162
"<div style='max-width: 300px; white-space: normal;'>" +
11631163
item.meta +
11641164
"</div>";
1165-
}
1165+
},
11661166
};
11671167
langTools.setCompleters([completer]);
11681168
editor.setOptions({
11691169
enableBasicAutocompletion: true,
1170-
enableLiveAutocompletion: true
1170+
enableLiveAutocompletion: true,
11711171
});
11721172

11731173
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
@@ -1176,5 +1176,5 @@ ko.bindingHandlers.aceEditor = {
11761176
});
11771177

11781178
editor.focus();
1179-
}
1179+
},
11801180
};

0 commit comments

Comments
 (0)