diff --git a/packages/survey-core/src/question_matrixdropdownbase.ts b/packages/survey-core/src/question_matrixdropdownbase.ts index 72b8c7ac95..06c54aa852 100644 --- a/packages/survey-core/src/question_matrixdropdownbase.ts +++ b/packages/survey-core/src/question_matrixdropdownbase.ts @@ -1477,6 +1477,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel, properties: HashTable): void { + const oldRowVariables = values[MatrixDropdownRowModelBase.RowVariableName]; super.runCondition(values, properties); var counter = 0; var prevTotalValue; @@ -1490,6 +1491,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModelsurvey.getQuestionByName("matrix"); - assert.equal( - matrix.detailPanelMode, - "underRow", - "detail panel mode load correctly" - ); - assert.equal( - matrix.detailElements.length, - 4, - "detail elements loads correctly" - ); + const matrix = survey.getQuestionByName("matrix"); + assert.equal(matrix.detailPanelMode, "underRow", "detail panel mode load correctly"); + assert.equal(matrix.detailElements.length, 4, "detail elements loads correctly"); matrix.visibleRows[0].showDetailPanel(); assert.ok(matrix.visibleRows[0].detailPanel, "Detail Panel is created"); - var panel = matrix.visibleRows[0].detailPanel; - assert.equal( - panel.questions[0].isVisible, - false, - "first question is invisible" - ); - assert.equal( - panel.questions[1].isVisible, - false, - "second question is invisible" - ); - assert.equal( - panel.questions[2].isVisible, - false, - "third question is invisible" - ); - assert.equal( - panel.questions[3].isVisible, - true, - "fourth question is invisible" - ); + const panel = matrix.visibleRows[0].detailPanel; + assert.equal(panel.questions[0].isVisible, false, "first question is invisible"); + assert.equal(panel.questions[1].isVisible, false, "second question is invisible"); + assert.equal(panel.questions[2].isVisible, false, "third question is invisible"); + assert.equal(panel.questions[3].isVisible, true, "fourth question is invisible"); survey.setValue("question1", "val1"); - assert.equal( - panel.questions[0].isVisible, - true, - "first question is visible now" - ); - assert.equal( - panel.questions[3].isVisible, - false, - "fourth question is invisible now" - ); + assert.equal(panel.questions[0].isVisible, true, "first question is visible now"); + assert.equal(panel.questions[3].isVisible, false, "fourth question is invisible now"); matrix.visibleRows[0].cells[0].question.value = "val2"; - assert.equal( - panel.questions[1].isVisible, - true, - "second question is visible now" - ); + assert.equal(panel.questions[1].isVisible, true, "second question is visible now"); panel.getQuestionByName("q2").value = "val3"; - assert.equal( - panel.questions[2].isVisible, - true, - "third question is visible now" - ); + assert.equal(panel.questions[2].isVisible, true, "third question is visible now"); +}); +QUnit.test("Detail panel, run conditions & matrix before elements, bug#9137", function (assert) { + const survey = new SurveyModel({ + elements: [ + { + type: "matrixdynamic", + name: "matrix", + rowCount: 2, + detailPanelMode: "underRow", + columns: [{ name: "col1" }, { name: "col2" }], + cellType: "text", + detailElements: [ + { type: "matrixdynamic", name: "m1", columns: [{ name: "col1", defaultValue: "v1" }, { name: "col2", visibleIf: "{row.col1} notempty" }] }, + { type: "text", name: "q1", visibleIf: "{row.col1} = 'val2'" }, + { type: "text", name: "q2", visibleIf: "{row.q1} = 'val3'" } + ] + } + ] + }); + const matrix = survey.getQuestionByName("matrix"); + matrix.visibleRows[0].showDetailPanel(); + assert.ok(matrix.visibleRows[0].detailPanel, "Detail Panel is created"); + const panel = matrix.visibleRows[0].detailPanel; + assert.equal(panel.getQuestionByName("m1").visibleRows.length, 2, "nested matrix rows are created"); + assert.equal(panel.getQuestionByName("q1").isVisible, false, "first question is invisible, #1"); + assert.equal(panel.getQuestionByName("q2").isVisible, false, "second question is invisible, #1"); + matrix.visibleRows[0].cells[0].question.value = "val2"; + assert.equal(panel.getQuestionByName("q1").isVisible, true, "first question is visible, #2"); + assert.equal(panel.getQuestionByName("q2").isVisible, false, "second question is invisible, #2"); + panel.getQuestionByName("q1").value = "val3"; + assert.equal(panel.getQuestionByName("q1").isVisible, true, "first question is visible, #3"); + assert.equal(panel.getQuestionByName("q2").isVisible, true, "second question is visible, #3"); }); QUnit.test("Detail panel and defaultValueFromLastRow", function (assert) { var survey = new SurveyModel({