diff --git a/src/conditionProcessValue.ts b/src/conditionProcessValue.ts index 5d9be973e8..6da2c8e206 100644 --- a/src/conditionProcessValue.ts +++ b/src/conditionProcessValue.ts @@ -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] !== "[") { diff --git a/tests/question_matrixdynamictests.ts b/tests/question_matrixdynamictests.ts index c0f7c22d8b..103b58b298 100644 --- a/tests/question_matrixdynamictests.ts +++ b/tests/question_matrixdynamictests.ts @@ -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 = survey.getQuestionByName("q1"); + var q2 = 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" + ); +}); diff --git a/tests/textPreprocessorTests.ts b/tests/textPreprocessorTests.ts index a756c37359..85d33ed1de 100644 --- a/tests/textPreprocessorTests.ts +++ b/tests/textPreprocessorTests.ts @@ -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); @@ -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) {