Skip to content

Commit

Permalink
Multi-Select Matrix - The 'Cannot read properties of null (reading 'l…
Browse files Browse the repository at this point in the history
…ength')' exception is thrown when hideIfRowsEmpty is enabled fix #8824 (#8829)
  • Loading branch information
andrewtelnov committed Sep 19, 2024
1 parent 45fe24f commit 4cbba56
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/survey-core/src/martixBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class QuestionMatrixBaseModel<TRow, TColumn> extends Question {
protected isVisibleCore(): boolean {
const res = super.isVisibleCore();
if(!res || !(<any>this).hideIfRowsEmpty) return res;
return this.visibleRows.length > 0;
return this.visibleRows?.length > 0;
}
protected shouldRunColumnExpression(): boolean {
return !this.survey || !this.survey.areInvisibleElementsShowing;
Expand Down
1 change: 1 addition & 0 deletions packages/survey-core/src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
!Helpers.isTwoValueEquals(prevTotalValue, this.totalValue) &&
counter < 3
);
this.updateVisibilityBasedOnRows();
}
public runTriggers(name: string, value: any): void {
super.runTriggers(name, value);
Expand Down
17 changes: 17 additions & 0 deletions packages/survey-core/tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8614,6 +8614,23 @@ QUnit.test("Test property hideIfRowsEmpty for matrix dropdown", function (assert
survey.setValue("val1", 2);
assert.equal(question.isVisible, true, "There is one visible item");
});
QUnit.test("Test property hideIfRowsEmpty for matrix dropdown on loading, Bug#8824", function (assert) {
var survey = new SurveyModel({
elements: [
{ type: "text", name: "q1" },
{ type: "matrixdropdown", name: "matrix", rowsVisibleIf: "{q1} != 'a'",
columns: [{ name: "col1", cellType: "text" }],
rows: ["row1", "row2"], hideIfRowsEmpty: true
}
]
});
const matrix = survey.getQuestionByName("matrix");
assert.equal(matrix.getPropertyValue("isVisible"), true, "#1");
survey.setValue("q1", "a");
assert.equal(matrix.getPropertyValue("isVisible"), false, "#2");
survey.setValue("q1", "aa");
assert.equal(matrix.getPropertyValue("isVisible"), true, "#3");
});

QUnit.test("Load old JSON where columns without cellType set correctly", function (assert) {
const survey = new SurveyModel({
Expand Down

0 comments on commit 4cbba56

Please sign in to comment.