Skip to content

Commit

Permalink
Merge pull request #8613 from surveyjs/bug/8612-composite-component-d…
Browse files Browse the repository at this point in the history
…ynamic-panel-reset

Composite Questions - A newly added Dynamic Panel disappears when mod…
  • Loading branch information
OlgaLarina authored Jul 25, 2024
2 parents d5e402e + 29052db commit a66a01b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/question_custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ export class QuestionCompositeModel extends QuestionCustomModelBase {
const key = questions[i].getValueName();
const val = !!newValue ? newValue[key] : undefined;
const q = questions[i];
if(!this.isTwoValueEquals(q.value, val)) {
if(!this.isTwoValueEquals(q.value, val) && (val !== undefined || !q.isEmpty())) {
q.value = val;
}
}
Expand Down
53 changes: 53 additions & 0 deletions tests/question_customtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3270,3 +3270,56 @@ QUnit.test("single component: inheritBaseProps - do not duplicate description pr
assert.equal(descriptionCounter, 1, "We have one description property");
ComponentCollection.Instance.clear();
});
QUnit.test("composite component: do not reset dynamic panels/dynamic rows, Bug#8612", function (assert) {
ComponentCollection.Instance.add({
name: "customquestion",
elementsJSON: [
{
type: "text",
name: "qText",
},
{
"type": "paneldynamic",
"name": "panel",
"templateElements": [
{
"type": "text",
"name": "question2"
}
]
},
{
"type": "matrixdynamic",
"name": "matrix",
"rowCount": 0,
"columns": [
{
"cellType": "text",
"name": "col1"
}
]
}
]
});

const survey = new SurveyModel({
elements: [
{ type: "customquestion", name: "q1" }
]
});
const q1 = <QuestionCompositeModel>survey.getQuestionByName("q1");
const panel = <QuestionPanelDynamicModel>q1.contentPanel.getQuestionByName("panel");
const matrix = <QuestionMatrixDynamicModel>q1.contentPanel.getQuestionByName("matrix");
const text = q1.contentPanel.getQuestionByName("qText");
panel.addPanel();
panel.addPanel();
panel.addPanel();
matrix.addRow();
matrix.addRow();
matrix.addRow();
text.value = "abc";
assert.equal(matrix.rowCount, 3, "There are 3 rows");
assert.equal(panel.panelCount, 3, "There are 3 panels");

ComponentCollection.Instance.clear();
});

0 comments on commit a66a01b

Please sign in to comment.