From 654498d0bfdcf9aa0b91b3bd39cc9b30a40a498b Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 10 Jan 2025 13:46:46 +0000 Subject: [PATCH] Multi-Select Matrix - The rowsVisibleIf expression should not be evaluated/applied at design time fix #9279 (#9285) --- packages/survey-core/src/martixBase.ts | 4 ++-- .../survey-core/src/question_baseselect.ts | 4 ++-- packages/survey-core/src/question_custom.ts | 8 +++---- .../survey-core/src/question_expression.ts | 4 ++-- packages/survey-core/src/question_matrix.ts | 4 ++-- .../src/question_matrixdropdownbase.ts | 5 +++-- .../survey-core/src/question_multipletext.ts | 4 ++-- .../survey-core/src/question_paneldynamic.ts | 4 ++-- packages/survey-core/src/question_text.ts | 4 ++-- .../tests/question_matrixdynamictests.ts | 22 +++++++++++++++++++ 10 files changed, 43 insertions(+), 20 deletions(-) diff --git a/packages/survey-core/src/martixBase.ts b/packages/survey-core/src/martixBase.ts index 898f7fecdc..9ae53b8eae 100644 --- a/packages/survey-core/src/martixBase.ts +++ b/packages/survey-core/src/martixBase.ts @@ -137,8 +137,8 @@ export class QuestionMatrixBaseModel extends Question { this.runCondition(this.getDataFilteredValues(), this.getDataFilteredProperties()); } } - public runCondition(values: HashTable, properties: HashTable): void { - super.runCondition(values, properties); + protected runConditionCore(values: HashTable, properties: HashTable): void { + super.runConditionCore(values, properties); this.runItemsCondition(values, properties); } protected onColumnsChanged(): void { } diff --git a/packages/survey-core/src/question_baseselect.ts b/packages/survey-core/src/question_baseselect.ts index 32ffa7c4a5..8490ce4236 100644 --- a/packages/survey-core/src/question_baseselect.ts +++ b/packages/survey-core/src/question_baseselect.ts @@ -386,8 +386,8 @@ export class QuestionSelectBase extends Question { public surveyChoiceItemVisibilityChange(): void { this.filterItems(); } - public runCondition(values: HashTable, properties: HashTable): void { - super.runCondition(values, properties); + protected runConditionCore(values: HashTable, properties: HashTable): void { + super.runConditionCore(values, properties); this.runItemsEnableCondition(values, properties); this.runItemsCondition(values, properties); this.choices.forEach(item => { diff --git a/packages/survey-core/src/question_custom.ts b/packages/survey-core/src/question_custom.ts index dddb4e5966..f5aa005efc 100644 --- a/packages/survey-core/src/question_custom.ts +++ b/packages/survey-core/src/question_custom.ts @@ -920,8 +920,8 @@ export class QuestionCustomModel extends QuestionCustomModelBase { this.value = this.getContentQuestionValue(); } } - public runCondition(values: HashTable, properties: HashTable) { - super.runCondition(values, properties); + protected runConditionCore(values: HashTable, properties: HashTable): void { + super.runConditionCore(values, properties); if (!!this.contentQuestion) { this.contentQuestion.runCondition(values, properties); } @@ -1196,8 +1196,8 @@ export class QuestionCompositeModel extends QuestionCustomModelBase { } return res; } - public runCondition(values: HashTable, properties: HashTable): void { - super.runCondition(values, properties); + protected runConditionCore(values: HashTable, properties: HashTable): void { + super.runConditionCore(values, properties); if (!!this.contentPanel) { var oldComposite = values[QuestionCompositeModel.ItemVariableName]; values[ diff --git a/packages/survey-core/src/question_expression.ts b/packages/survey-core/src/question_expression.ts index 2b78bd3f2d..754f75baad 100644 --- a/packages/survey-core/src/question_expression.ts +++ b/packages/survey-core/src/question_expression.ts @@ -62,8 +62,8 @@ export class QuestionExpressionModel extends Question { public unlocCalculation() { this.expressionIsRunning = false; } - public runCondition(values: HashTable, properties: HashTable) { - super.runCondition(values, properties); + protected runConditionCore(values: HashTable, properties: HashTable) { + super.runConditionCore(values, properties); if ( !this.expression || this.expressionIsRunning || diff --git a/packages/survey-core/src/question_matrix.ts b/packages/survey-core/src/question_matrix.ts index 552ba988ee..843512828c 100644 --- a/packages/survey-core/src/question_matrix.ts +++ b/packages/survey-core/src/question_matrix.ts @@ -435,9 +435,9 @@ export class QuestionMatrixModel } return res; } - public runCondition(values: HashTable, properties: HashTable): void { + protected runConditionCore(values: HashTable, properties: HashTable): void { ItemValue.runEnabledConditionsForItems(this.rows, undefined, values, properties); - super.runCondition(values, properties); + super.runConditionCore(values, properties); } protected createRowsVisibleIfRunner(): ConditionRunner { return !!this.rowsVisibleIf ? new ConditionRunner(this.rowsVisibleIf) : null; diff --git a/packages/survey-core/src/question_matrixdropdownbase.ts b/packages/survey-core/src/question_matrixdropdownbase.ts index a6f8a6a44a..719d3012d7 100644 --- a/packages/survey-core/src/question_matrixdropdownbase.ts +++ b/packages/survey-core/src/question_matrixdropdownbase.ts @@ -1483,9 +1483,9 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel, properties: HashTable): void { + protected runConditionCore(values: HashTable, properties: HashTable): void { const oldRowVariables = values[MatrixDropdownRowModelBase.RowVariableName]; - super.runCondition(values, properties); + super.runConditionCore(values, properties); var counter = 0; var prevTotalValue; do { @@ -1515,6 +1515,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel, properties: HashTable): void { + if(this.isDesignMode) return; const rows = this.generatedVisibleRows; if (!!rows) { const newValues = this.getRowConditionValues(values); diff --git a/packages/survey-core/src/question_multipletext.ts b/packages/survey-core/src/question_multipletext.ts index 3c6972b0cc..43d2fe65e1 100644 --- a/packages/survey-core/src/question_multipletext.ts +++ b/packages/survey-core/src/question_multipletext.ts @@ -707,8 +707,8 @@ export class QuestionMultipleTextModel extends Question this.items[i].onValueChanged(itemValue); } } - public runCondition(values: HashTable, properties: HashTable): void { - super.runCondition(values, properties); + protected runConditionCore(values: HashTable, properties: HashTable): void { + super.runConditionCore(values, properties); this.items.forEach(item => item.editor.runCondition(values, properties)); } protected getIsRunningValidators(): boolean { diff --git a/packages/survey-core/src/question_paneldynamic.ts b/packages/survey-core/src/question_paneldynamic.ts index b3e2abc58c..07bed4ef06 100644 --- a/packages/survey-core/src/question_paneldynamic.ts +++ b/packages/survey-core/src/question_paneldynamic.ts @@ -1877,8 +1877,8 @@ export class QuestionPanelDynamicModel extends Question this.panelsCore[i].localeChanged(); } } - public runCondition(values: HashTable, properties: HashTable): void { - super.runCondition(values, properties); + protected runConditionCore(values: HashTable, properties: HashTable): void { + super.runConditionCore(values, properties); this.runPanelsCondition(this.panelsCore, values, properties); } public runTriggers(name: string, value: any, keys?: any): void { diff --git a/packages/survey-core/src/question_text.ts b/packages/survey-core/src/question_text.ts index b84e3b51f6..49fd1f67fe 100644 --- a/packages/survey-core/src/question_text.ts +++ b/packages/survey-core/src/question_text.ts @@ -170,8 +170,8 @@ export class QuestionTextModel extends QuestionTextBase { if(!this.isTextInput) return null; return super.getMaxLength(); } - public runCondition(values: HashTable, properties: HashTable) { - super.runCondition(values, properties); + protected runConditionCore(values: HashTable, properties: HashTable): void { + super.runConditionCore(values, properties); if (!!this.minValueExpression || !!this.maxValueExpression) { this.setRenderedMinMax(values, properties); } diff --git a/packages/survey-core/tests/question_matrixdynamictests.ts b/packages/survey-core/tests/question_matrixdynamictests.ts index 82e1d07072..7368d4716f 100644 --- a/packages/survey-core/tests/question_matrixdynamictests.ts +++ b/packages/survey-core/tests/question_matrixdynamictests.ts @@ -2443,6 +2443,28 @@ QUnit.test("matrix dropdown rowsVisibleIf, use 'row.' context && total && add ne matrix.visibleRows[1].cells[1].value = 40; assert.equal(matrix.visibleTotalRow.cells[1].value, 50, "total sum #3"); }); +QUnit.test("matrix dropdown rowsVisibleIf, defaultValue & designMode, Bug#9279", function (assert) { + const json = { + elements: [ + { + type: "matrixdropdown", name: "matrix", + rowsVisibleIf: "{row.col1} != 'a'", cellType: "text", + columns: [{ name: "col1" }, { name: "col2" }], + defaultValue: { row1: { col1: "a", col2: 5 }, row2: { col1: "b", col2: 10 }, row3: { col1: "a", col2: 15 } }, + rows: ["row1", "row2", "row3"] + } + ] + }; + const survey = new SurveyModel(); + survey.setDesignMode(true); + survey.fromJSON(json); + let matrix = survey.getQuestionByName("matrix"); + assert.equal(matrix.visibleRows.length, 3, "show all rows"); + survey.setDesignMode(false); + survey.fromJSON(json); + matrix = survey.getQuestionByName("matrix"); + assert.equal(matrix.visibleRows.length, 1, "row1, row3 are hidden"); +}); QUnit.test("matrix dropdown rowsVisibleIf, use 'row.' context & set data correctly", function (assert) { var survey = new SurveyModel({ elements: [