Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The defaultValueExpression doesn't work for fields placed within a Dy… #6916

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});