From f0543f8ce8f6d3da44e825160502cd6b79b93090 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 9 Dec 2024 11:36:25 +0000 Subject: [PATCH] The row is added incorrectly if errors shows on the bottom and detail open is open in the last row fix #9147 (#9148) --- .../src/question_matrixdropdownrendered.ts | 7 +- .../tests/question_matrixdynamictests.ts | 72 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/packages/survey-core/src/question_matrixdropdownrendered.ts b/packages/survey-core/src/question_matrixdropdownrendered.ts index 3a45d7e7ae..1792498cec 100644 --- a/packages/survey-core/src/question_matrixdropdownrendered.ts +++ b/packages/survey-core/src/question_matrixdropdownrendered.ts @@ -396,7 +396,12 @@ export class QuestionMatrixDropdownRenderedTable extends Base { let dataRowIndex = 0; for (var i = 0; i < this.rows.length; i++) { if (dataRowIndex === index) { - if (this.rows[i].isErrorsRow || this.rows[i].isDetailRow) res++; + if (this.rows[i].isErrorsRow || this.rows[i].isDetailRow) { + res++; + if(i + 1 < this.rows.length && this.rows[i + 1].isDetailRow) { + res ++; + } + } break; } res++; diff --git a/packages/survey-core/tests/question_matrixdynamictests.ts b/packages/survey-core/tests/question_matrixdynamictests.ts index 806f4d9420..6edaa672db 100644 --- a/packages/survey-core/tests/question_matrixdynamictests.ts +++ b/packages/survey-core/tests/question_matrixdynamictests.ts @@ -9781,6 +9781,78 @@ QUnit.test("matrix dynamic detail panel & checkbox valuePropertyName & matrix dy matrix1 = rows[1].getQuestionByName("matrix1"); assert.deepEqual(matrix1.value, [{ prop1: 3 }], "#2"); }); +QUnit.test("matrix dynamic & detail panel, add a new row when the last row is expanded, errorLocation: 'bottom', Bug9147", function (assert) { + const survey = new SurveyModel({ + elements: [ + { + type: "matrixdynamic", + name: "matrix", + errorLocation: "bottom", + columns: [ + { + name: "col1", + cellType: "text" + } + ], + detailPanelMode: "underRow", + detailElements: [ + { + name: "q2", + type: "text" + } + ] + } + ] + }); + const matrix = survey.getQuestionByName("matrix"); + const rendredTable = matrix.renderedTable; + const rows = matrix.visibleRows; + rows[1].showDetailPanel(); + assert.equal(rendredTable.rows.length, 2 * 2 + 1, "There are 5 rows"); + assert.equal(rendredTable.rows[4].isDetailRow, true, "The last row is a detail row"); + matrix.addRow(); + assert.equal(rendredTable.rows.length, 3 * 2 + 1, "There are 7 rows"); + assert.equal(rendredTable.rows[4].isDetailRow, true, "The 5th row is a detail row"); + assert.equal(rendredTable.rows[5].cells[1].question.name, "col1", "The 6th row is a data row"); + assert.equal(rendredTable.rows[5].isDetailRow, false, "The 6th row is not a detail row"); + assert.equal(rendredTable.rows[6].isErrorsRow, true, "The 7th row is an error row"); + assert.equal(rendredTable.rows[6].isDetailRow, false, "The 7th row is not a detail row"); +}); +QUnit.test("matrix dynamic & detail panel, add a new row when the last row is expanded, errorLocation: 'top' (default), Bug9147", function (assert) { + const survey = new SurveyModel({ + elements: [ + { + type: "matrixdynamic", + name: "matrix", + columns: [ + { + name: "col1", + cellType: "text" + } + ], + detailPanelMode: "underRow", + detailElements: [ + { + name: "q2", + type: "text" + } + ] + } + ] + }); + const matrix = survey.getQuestionByName("matrix"); + const rendredTable = matrix.renderedTable; + const rows = matrix.visibleRows; + rows[1].showDetailPanel(); + assert.equal(rendredTable.rows.length, 2 * 2 + 1, "There are 5 rows"); + assert.equal(rendredTable.rows[4].isDetailRow, true, "The last row is a detail row"); + matrix.addRow(); + assert.equal(rendredTable.rows.length, 3 * 2 + 1, "There are 7 rows"); + assert.equal(rendredTable.rows[4].isDetailRow, true, "The 5th row is a detail row"); + assert.equal(rendredTable.rows[5].isErrorsRow, true, "The 6th row is an error row"); + assert.equal(rendredTable.rows[6].isDetailRow, false, "The 7th row is not a detail row"); + assert.equal(rendredTable.rows[6].cells[1].question.name, "col1", "The 7th row is a data row"); +}); QUnit.test("Totals alingment", function (assert) { var json = { pages: [