Skip to content

Commit

Permalink
Name rows correctly in getPlainData for matrix dynamic (#7375)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Nov 17, 2023
1 parent cb923d8 commit fe0ae50
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ implements ISurveyData, ISurveyImpl, ILocalizableOwner {
public get rowName(): any {
return null;
}
public get dataName(): string {
return this.rowName;
}
public get text(): any {
return this.rowName;
}
Expand Down Expand Up @@ -1767,7 +1770,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
questionPlainData.data = this.visibleRows.map(
(row: MatrixDropdownRowModelBase) => {
var rowDataItem = <any>{
name: row.rowName,
name: row.dataName,
title: row.text,
value: row.value,
displayValue: this.getRowDisplayValue(false, row, row.value),
Expand Down
6 changes: 6 additions & 0 deletions src/question_matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export class MatrixDynamicRowModel extends MatrixDropdownRowModelBase implements
public get rowName() {
return this.id;
}
public get dataName(): string {
return "row" + (this.index + 1);
}
public get text(): any {
return "row " + (this.index + 1);
}
public getAccessbilityText(): string {
return (this.index + 1).toString();
}
Expand Down
20 changes: 20 additions & 0 deletions tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8954,3 +8954,23 @@ QUnit.test("matrixdynamic.removeRow & confirmActionAsync, #6736", function (asse

settings.confirmActionAsync = prevAsync;
});
QUnit.test("matrix dynamic getPlainData", function (assert) {
const survey = new SurveyModel({
elements: [
{ type: "matrixdynamic", name: "matrix",
columns: [{ cellType: "text", name: "col1" }, { cellType: "text", name: "col2" }]
}
]
});
const q = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix");
q.value = [{ col1: 1, col2: 2 }, { col1: 3, col2: 4 }];
const data: any = survey.getPlainData();//["matrix"];
const row1Name = data[0].data[0].name;
const row1Title = data[0].data[0].title;
const row2Name = data[0].data[1].name;
const row2Title = data[0].data[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");
});

0 comments on commit fe0ae50

Please sign in to comment.