From 099d2e7e545736f9bbd550a2240cf3e593837301 Mon Sep 17 00:00:00 2001 From: Andrew Telnov Date: Fri, 8 Sep 2023 12:23:41 +0300 Subject: [PATCH] The defaultValueExpression doesn't work for fields placed within a Dynamic Panel which shares data with other Dynamic Pane (valueName) fix #6911 --- src/question.ts | 2 ++ tests/question_paneldynamic_tests.ts | 54 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/question.ts b/src/question.ts index 0550ff79f8..c65071ef7a 100644 --- a/src/question.ts +++ b/src/question.ts @@ -2080,7 +2080,9 @@ export class Question extends SurveyElement newValue = this.valueFromDataCallback(newValue); } if(!this.checkIsValueCorrect(newValue)) return; + this.isChangingViaDefaultValue = true; this.setQuestionValue(this.valueFromData(newValue)); + this.isChangingViaDefaultValue = false; this.updateDependedQuestions(); this.updateIsAnswered(); } diff --git a/tests/question_paneldynamic_tests.ts b/tests/question_paneldynamic_tests.ts index 34a9c0c1d2..4e65a82633 100644 --- a/tests/question_paneldynamic_tests.ts +++ b/tests/question_paneldynamic_tests.ts @@ -6133,3 +6133,57 @@ QUnit.test("nested panel.panelCount&expression question", function (assert) { const panel1 = rootPanel.panels[0].getQuestionByName("panel2"); assert.equal(panel1.panels.length, 3, "It should be 3 panels"); }); +QUnit.test("nested panel.panelCount&expression question", function (assert) { + const survey = new SurveyModel({ + "elements": [ + { + "type": "paneldynamic", + "name": "panel1", + "valueName": "shared", + "templateElements": [ + { + "type": "text", + "name": "A" + } + ], + "panelCount": 1 + }, + { + "type": "paneldynamic", + "name": "panel2", + "valueName": "shared", + "templateElements": [ + { + "type": "text", + "name": "B" + }, + { + "type": "text", + "name": "C", + "defaultValueExpression": "{panel.A}", + "readOnly": true + }, + { + "type": "text", + "name": "D", + "defaultValueExpression": "{panel.B}+{panel.C}", + "readOnly": true + }, + { + "type": "expression", + "name": "E", + "expression": "{panel.B}+{panel.C}" + } + ] + } + ] + }); + const panel1 = survey.getQuestionByName("panel1"); + panel1.panels[0].getQuestionByName("A").value = 1; + const panel2 = survey.getQuestionByName("panel2"); + const panel = panel2.panels[0]; + panel.getQuestionByName("B").value = 2; + assert.equal(panel.getQuestionByName("C").value, 1, "C"); + assert.equal(panel.getQuestionByName("D").value, 3, "D"); + assert.equal(panel.getQuestionByName("E").value, 3, "E"); +}); \ No newline at end of file