Skip to content

Commit

Permalink
Dynamic Matrix with detail elements - Conditional visibility within a…
Browse files Browse the repository at this point in the history
… detail panel stops working when another dynamic panel is placed within a detail form fix #9137 (#9143)
  • Loading branch information
andrewtelnov authored Dec 6, 2024
1 parent c1f2817 commit 2322a30
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 52 deletions.
2 changes: 2 additions & 0 deletions packages/survey-core/src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
}
}
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
const oldRowVariables = values[MatrixDropdownRowModelBase.RowVariableName];
super.runCondition(values, properties);
var counter = 0;
var prevTotalValue;
Expand All @@ -1490,6 +1491,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
counter < 3
);
this.updateVisibilityBasedOnRows();
values[MatrixDropdownRowModelBase.RowVariableName] = oldRowVariables;
}
public runTriggers(name: string, value: any, keys?: any): void {
super.runTriggers(name, value, keys);
Expand Down
96 changes: 44 additions & 52 deletions packages/survey-core/tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6669,63 +6669,55 @@ QUnit.test("Detail panel, run conditions", function (assert) {
},
],
});
var matrix = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix");
assert.equal(
matrix.detailPanelMode,
"underRow",
"detail panel mode load correctly"
);
assert.equal(
matrix.detailElements.length,
4,
"detail elements loads correctly"
);
const matrix = <QuestionMatrixDynamicModel>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 = <QuestionMatrixDynamicModel>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({
Expand Down

0 comments on commit 2322a30

Please sign in to comment.