Skip to content

Commit

Permalink
Fix: ProcessValue class doesn't correctly create path for uppercase v…
Browse files Browse the repository at this point in the history
…ariables. #2571
  • Loading branch information
andrewtelnov committed Dec 13, 2020
1 parent c0a549a commit 784b442
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/conditionProcessValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@ export class ProcessValue {
if (!name) return name;
if (!obj) obj = {};
if (obj.hasOwnProperty(name)) return name;
name = name.toLowerCase();
var A = name[0];
var nameInLow = name.toLowerCase();
var A = nameInLow[0];
var a = A.toUpperCase();
for (var key in obj) {
var first = key[0];
if (first === a || first === A) {
var keyName = key.toLowerCase();
if (keyName == name) return key;
if (name.length <= keyName.length) continue;
var ch = name[keyName.length];
if (keyName == nameInLow) return key;
if (nameInLow.length <= keyName.length) continue;
var ch = nameInLow[keyName.length];
if (ch != "." && ch != "[") continue;
if (keyName == name.substr(0, keyName.length)) return key;
if (keyName == nameInLow.substr(0, keyName.length)) return key;
}
}
if (createProp && name[0] !== "[") {
Expand Down
57 changes: 57 additions & 0 deletions tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5406,3 +5406,60 @@ QUnit.test("Detail panel, Process text in titles", function (assert) {
"Text preprocessed correctly"
);
});

QUnit.test("copyvalue trigger for dropdown matrix cell", function (assert) {
var survey = new SurveyModel({
elements: [
{
type: "matrixdropdown",
name: "q1",
rows: ["item1", "Item2"],
columns: [{ name: "c1", cellType: "text" }],
},
{
type: "matrixdropdown",
name: "q2",
rows: ["item1", "Item2"],
columns: [{ name: "c1", cellType: "text" }],
},
],
triggers: [
{
type: "copyvalue",
expression: "{q1.item1.c1} notempty",
setToName: "q2.item1.c1",
fromName: "q1.item1.c1",
},
{
type: "copyvalue",
expression: "{q1.Item2.c1} notempty",
setToName: "q2.Item2.c1",
fromName: "q1.Item2.c1",
},
],
});
var q1 = <QuestionMatrixDynamicModel>survey.getQuestionByName("q1");
var q2 = <QuestionMatrixDynamicModel>survey.getQuestionByName("q2");
q1.visibleRows[0].cells[0].value = "val1";
q1.visibleRows[1].cells[0].value = "val2";
assert.equal(
q2.visibleRows[0].cells[0].value,
"val1",
"copy value for item1"
);
assert.equal(
survey.runCondition("{q1.Item2.c1} notempty"),
true,
"The expression returns true"
);
assert.equal(
survey.runExpression("{q1.Item2.c1}"),
"val2",
"The expression returns val2"
);
assert.equal(
q2.visibleRows[1].cells[0].value,
"val2",
"copy value for Item2"
);
});
9 changes: 8 additions & 1 deletion tests/textPreprocessorTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ QUnit.test("ProcessValue setValue function", function (assert) {

QUnit.test("ProcessValue setValue function - create path", function (assert) {
var processor = new ProcessValue();
var data = { a: {}, b: 1 };
var data: any = { a: {}, b: 1 };
processor.setValue(data, "a.b", 1);
assert.deepEqual(data, { a: { b: 1 }, b: 1 }, "set the object inside");
processor.setValue(data, "c.a.b", 2);
Expand All @@ -157,6 +157,13 @@ QUnit.test("ProcessValue setValue function - create path", function (assert) {
{ a: { b: 1 }, b: 1, c: { a: { b: 2 } } },
"create new object"
);
data = { a: { Item1: { c1: 0 }, Item3: { c1: 1 } } };
processor.setValue(data, "a.Item1.c1", 1);
processor.setValue(data, "a.Item2.c1", 2);
processor.setValue(data, "a.Item3.c1", 3);
assert.deepEqual(data, {
a: { Item1: { c1: 1 }, Item2: { c1: 2 }, Item3: { c1: 3 } },
});
});

QUnit.test("ProcessValue setValue function for arrays", function (assert) {
Expand Down

0 comments on commit 784b442

Please sign in to comment.