Skip to content

Commit

Permalink
Multi-Select Matrix - The rowsVisibleIf expression should not be eval…
Browse files Browse the repository at this point in the history
…uated/applied at design time fix #9279 (#9285)
  • Loading branch information
andrewtelnov authored Jan 10, 2025
1 parent 2d3ca1a commit 654498d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/survey-core/src/martixBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export class QuestionMatrixBaseModel<TRow, TColumn> extends Question {
this.runCondition(this.getDataFilteredValues(), this.getDataFilteredProperties());
}
}
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
super.runCondition(values, properties);
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): void {
super.runConditionCore(values, properties);
this.runItemsCondition(values, properties);
}
protected onColumnsChanged(): void { }
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_baseselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ export class QuestionSelectBase extends Question {
public surveyChoiceItemVisibilityChange(): void {
this.filterItems();
}
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
super.runCondition(values, properties);
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): void {
super.runConditionCore(values, properties);
this.runItemsEnableCondition(values, properties);
this.runItemsCondition(values, properties);
this.choices.forEach(item => {
Expand Down
8 changes: 4 additions & 4 deletions packages/survey-core/src/question_custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ export class QuestionCustomModel extends QuestionCustomModelBase {
this.value = this.getContentQuestionValue();
}
}
public runCondition(values: HashTable<any>, properties: HashTable<any>) {
super.runCondition(values, properties);
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): void {
super.runConditionCore(values, properties);
if (!!this.contentQuestion) {
this.contentQuestion.runCondition(values, properties);
}
Expand Down Expand Up @@ -1196,8 +1196,8 @@ export class QuestionCompositeModel extends QuestionCustomModelBase {
}
return res;
}
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
super.runCondition(values, properties);
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): void {
super.runConditionCore(values, properties);
if (!!this.contentPanel) {
var oldComposite = values[QuestionCompositeModel.ItemVariableName];
values[
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class QuestionExpressionModel extends Question {
public unlocCalculation() {
this.expressionIsRunning = false;
}
public runCondition(values: HashTable<any>, properties: HashTable<any>) {
super.runCondition(values, properties);
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>) {
super.runConditionCore(values, properties);
if (
!this.expression ||
this.expressionIsRunning ||
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ export class QuestionMatrixModel
}
return res;
}
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): 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;
Expand Down
5 changes: 3 additions & 2 deletions packages/survey-core/src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1483,9 +1483,9 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
}
}
}
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): void {
const oldRowVariables = values[MatrixDropdownRowModelBase.RowVariableName];
super.runCondition(values, properties);
super.runConditionCore(values, properties);
var counter = 0;
var prevTotalValue;
do {
Expand Down Expand Up @@ -1515,6 +1515,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
return false;
}
protected runCellsCondition(values: HashTable<any>, properties: HashTable<any>): void {
if(this.isDesignMode) return;
const rows = this.generatedVisibleRows;
if (!!rows) {
const newValues = this.getRowConditionValues(values);
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_multipletext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ export class QuestionMultipleTextModel extends Question
this.items[i].onValueChanged(itemValue);
}
}
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
super.runCondition(values, properties);
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): void {
super.runConditionCore(values, properties);
this.items.forEach(item => item.editor.runCondition(values, properties));
}
protected getIsRunningValidators(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1877,8 +1877,8 @@ export class QuestionPanelDynamicModel extends Question
this.panelsCore[i].localeChanged();
}
}
public runCondition(values: HashTable<any>, properties: HashTable<any>): void {
super.runCondition(values, properties);
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): void {
super.runConditionCore(values, properties);
this.runPanelsCondition(this.panelsCore, values, properties);
}
public runTriggers(name: string, value: any, keys?: any): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export class QuestionTextModel extends QuestionTextBase {
if(!this.isTextInput) return null;
return super.getMaxLength();
}
public runCondition(values: HashTable<any>, properties: HashTable<any>) {
super.runCondition(values, properties);
protected runConditionCore(values: HashTable<any>, properties: HashTable<any>): void {
super.runConditionCore(values, properties);
if (!!this.minValueExpression || !!this.maxValueExpression) {
this.setRenderedMinMax(values, properties);
}
Expand Down
22 changes: 22 additions & 0 deletions packages/survey-core/tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix");
assert.equal(matrix.visibleRows.length, 3, "show all rows");
survey.setDesignMode(false);
survey.fromJSON(json);
matrix = <QuestionMatrixDynamicModel>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: [
Expand Down

0 comments on commit 654498d

Please sign in to comment.