From 089ee9784b83f1cf3ba73f344b014cc600303c55 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 3 Jul 2024 10:21:13 +0300 Subject: [PATCH] Matrix question configured with visible if condition and 'Hide the question if it has no rows"= True #8495 (#8499) --- src/martixBase.ts | 9 ++++++--- tests/question_matrix_tests.ts | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/martixBase.ts b/src/martixBase.ts index ba9158e8a9..5edb1c3d06 100644 --- a/src/martixBase.ts +++ b/src/martixBase.ts @@ -154,11 +154,14 @@ export class QuestionMatrixBaseModel extends Question { } protected updateVisibilityBasedOnRows(): void { if ((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 || !(this).hideIfRowsEmpty) return res; + return this.rows.length > 0 && (!this.filteredRows || this.filteredRows.length > 0); + } protected shouldRunColumnExpression(): boolean { return !this.survey || !this.survey.areInvisibleElementsShowing; } diff --git a/tests/question_matrix_tests.ts b/tests/question_matrix_tests.ts index 222dd24e9e..90b62364af 100644 --- a/tests/question_matrix_tests.ts +++ b/tests/question_matrix_tests.ts @@ -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 = 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"); +});