Skip to content

Commit

Permalink
A comment text of matrix questions is not returned by the survey.getP…
Browse files Browse the repository at this point in the history
…lainData function result fix #7433 (#7449)
  • Loading branch information
andrewtelnov authored Nov 30, 2023
1 parent 4cc3253 commit f4e7f6c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
var questionPlainData = super.getPlainData(options);
if (!!questionPlainData) {
questionPlainData.isNode = true;
const prevData = Array.isArray(questionPlainData.data) ? [].concat(questionPlainData.data) : [];
questionPlainData.data = this.visibleRows.map(
(row: MatrixDropdownRowModelBase) => {
var rowDataItem = <any>{
Expand All @@ -1791,6 +1792,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
return rowDataItem;
}
);
questionPlainData.data = questionPlainData.data.concat(prevData);
}
return questionPlainData;
}
Expand Down
2 changes: 2 additions & 0 deletions src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,7 @@ export class QuestionPanelDynamicModel extends Question
var questionPlainData = super.getPlainData(options);
if (!!questionPlainData) {
questionPlainData.isNode = true;
const prevData = Array.isArray(questionPlainData.data) ? [].concat(questionPlainData.data) : [];
questionPlainData.data = this.panels.map(
(panel: PanelModel, index: number) => {
var panelDataItem = <any>{
Expand All @@ -2001,6 +2002,7 @@ export class QuestionPanelDynamicModel extends Question
return panelDataItem;
}
);
questionPlainData.data = questionPlainData.data.concat(prevData);
}
return questionPlainData;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8974,3 +8974,29 @@ QUnit.test("matrix dynamic getPlainData", function (assert) {
assert.equal(row2Name, "row2", "row2 name");
assert.equal(row2Title, "row 2", "row2 title");
});
QUnit.test("matrix dynamic getPlainData & comment", function (assert) {
const survey = new SurveyModel({
elements: [
{ type: "matrixdynamic", name: "matrix",
columns: [{ cellType: "text", name: "col1" }, { cellType: "text", name: "col2" }],
showCommentArea: true
}
]
});
const q = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix");
q.value = [{ col1: 1, col2: 2 }, { col1: 3, col2: 4 }];
q.comment = "Some comments";
const data: any = survey.getPlainData();//["matrix"];
const qData = data[0].data;
assert.equal(qData.length, 3, "There are 3 records");
const row1Name = qData[0].name;
const row1Title = qData[0].title;
const row2Name = qData[1].name;
const row2Title = qData[1].title;
assert.equal(row1Name, "row1", "row1 name");
assert.equal(row1Title, "row 1", "row1 title");
assert.equal(row2Name, "row2", "row2 name");
assert.equal(row2Title, "row 2", "row2 title");
assert.equal(qData[2].title, "Comment", "comment title");
assert.equal(qData[2].isComment, true, "comment isComment");
});
23 changes: 23 additions & 0 deletions tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6433,3 +6433,26 @@ QUnit.test("question.setValueIf, basic functionality", function (assert) {
q3.value = 5;
assert.equal(q2.value, "klm", "value is set, #6");
});
QUnit.test("panel dynamic getPlainData & comment", function (assert) {
const survey = new SurveyModel({
elements: [
{
type: "paneldynamic",
name: "panel",
templateElements: [
{ name: "q1", type: "text" },
{ name: "q2", type: "text" }
],
showCommentArea: true
}
]
});
const q = survey.getQuestionByName("panel");
q.value = [{ q1: 1, q2: 2 }, { q1: 3, q2: 4 }];
q.comment = "Some comments";
const data: any = survey.getPlainData();
const qData = data[0].data;
assert.equal(qData.length, 3, "There are 3 records");
assert.equal(qData[2].title, "Comment", "comment title");
assert.equal(qData[2].isComment, true, "comment isComment");
});

0 comments on commit f4e7f6c

Please sign in to comment.