Skip to content

Commit

Permalink
The defaultValueExpression doesn't work for fields placed within a Dy…
Browse files Browse the repository at this point in the history
…namic Panel which shares data with other Dynamic Pane (valueName) fix #6911 (#6916)
  • Loading branch information
andrewtelnov committed Sep 10, 2023
1 parent bbbf8f2 commit 275ec8a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,9 @@ export class Question extends SurveyElement<Question>
newValue = this.valueFromDataCallback(newValue);
}
if(!this.checkIsValueCorrect(newValue)) return;
this.isChangingViaDefaultValue = true;
this.setQuestionValue(this.valueFromData(newValue));
this.isChangingViaDefaultValue = false;
this.updateDependedQuestions();
this.updateIsAnswered();
}
Expand Down
54 changes: 54 additions & 0 deletions tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionPanelDynamicModel>survey.getQuestionByName("panel1");
panel1.panels[0].getQuestionByName("A").value = 1;
const panel2 = <QuestionPanelDynamicModel>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");
});

0 comments on commit 275ec8a

Please sign in to comment.