Skip to content

Commit

Permalink
Matrix question configured with visible if condition and 'Hide the qu…
Browse files Browse the repository at this point in the history
…estion if it has no rows"= True #8495 (#8499)
  • Loading branch information
andrewtelnov authored Jul 3, 2024
1 parent f0c0d0b commit 089ee97
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/martixBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,14 @@ export class QuestionMatrixBaseModel<TRow, TColumn> extends Question {
}
protected updateVisibilityBasedOnRows(): void {
if ((<any>this).hideIfRowsEmpty) {
this.visible =
this.rows.length > 0 &&
(!this.filteredRows || this.filteredRows.length > 0);
this.onVisibleChanged();
}
}
protected isVisibleCore(): boolean {
const res = super.isVisibleCore();
if(!res || !(<any>this).hideIfRowsEmpty) return res;
return this.rows.length > 0 && (!this.filteredRows || this.filteredRows.length > 0);
}
protected shouldRunColumnExpression(): boolean {
return !this.survey || !this.survey.areInvisibleElementsShowing;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/question_matrix_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,22 @@ QUnit.test("matrix isAllRowRequired & getItemClass", function (assert) {
assert.equal(question.getItemClass(row, column1).indexOf(itemError) > -1, false, "itemError doesn't exist in column 1, #3");
assert.equal(question.getItemClass(row, column2).indexOf(itemError) > -1, false, "itemError doesn't exist in column 2, #3");
});
QUnit.test("hideIfRowsEmpty & question visibleIf, bug#8459", function (assert) {
const survey = new SurveyModel({
elements: [{ type: "matrix", name: "q1", visibleIf: "{a}=1", hideIfRowsEmpty: true, rows: [{ value: "row1", visibleIf: "{b}=2" }] }],
});
const question = <QuestionMatrixModel>survey.getQuestionByName("q1");
assert.equal(question.isVisible, false, "#1");
survey.setValue("a", 1);
assert.equal(question.isVisible, false, "#2");
survey.setValue("b", 2);
assert.equal(question.isVisible, true, "#3");
survey.setValue("a", 2);
assert.equal(question.isVisible, false, "#4");
survey.setValue("a", 1);
assert.equal(question.isVisible, true, "#5");
survey.setValue("b", 1);
assert.equal(question.isVisible, false, "#6");
survey.setValue("b", 2);
assert.equal(question.isVisible, true, "#7");
});

0 comments on commit 089ee97

Please sign in to comment.