diff --git a/src/question_matrixdropdowncolumn.ts b/src/question_matrixdropdowncolumn.ts index 2975fe4964..a8c39a5072 100644 --- a/src/question_matrixdropdowncolumn.ts +++ b/src/question_matrixdropdowncolumn.ts @@ -933,31 +933,31 @@ Serializer.addClass( classNamePart: "validator", }, { - name: "totalType", + name: "totalType", visibleIf: (obj: any): boolean => !obj.isShowInMultipleColumns, default: "none", choices: ["none", "sum", "count", "min", "max", "avg"], }, - "totalExpression:expression", - { name: "totalFormat", serializationProperty: "locTotalFormat" }, + { name: "totalExpression:expression", visibleIf: (obj: any): boolean => !obj.isShowInMultipleColumns }, + { name: "totalFormat", serializationProperty: "locTotalFormat", visibleIf: (obj: any): boolean => obj.hasTotal }, { - name: "totalDisplayStyle", + name: "totalDisplayStyle", visibleIf: (obj: any): boolean => obj.hasTotal, default: "none", choices: ["none", "decimal", "currency", "percent"], }, { - name: "totalAlignment", + name: "totalAlignment", visibleIf: (obj: any): boolean => obj.hasTotal, default: "auto", choices: ["auto", "left", "center", "right"], }, { - name: "totalCurrency", + name: "totalCurrency", visibleIf: (obj: any): boolean => obj.hasTotal, choices: () => { return getCurrecyCodes(); }, default: "USD", }, - { name: "totalMaximumFractionDigits:number", default: -1 }, - { name: "totalMinimumFractionDigits:number", default: -1 }, + { name: "totalMaximumFractionDigits:number", default: -1, visibleIf: (obj: any): boolean => obj.hasTotal }, + { name: "totalMinimumFractionDigits:number", default: -1, visibleIf: (obj: any): boolean => obj.hasTotal }, { name: "renderAs", default: "default", visible: false }, ], function () { diff --git a/tests/question_matrixdropdownbasetests.ts b/tests/question_matrixdropdownbasetests.ts index e1e8dc1156..23f128721e 100644 --- a/tests/question_matrixdropdownbasetests.ts +++ b/tests/question_matrixdropdownbasetests.ts @@ -1,4 +1,4 @@ -import { Serializer } from "../src/jsonobject"; +import { JsonObjectProperty, Serializer } from "../src/jsonobject"; import { QuestionDropdownModel } from "../src/question_dropdown"; import { QuestionMatrixDropdownModelBase } from "../src/question_matrixdropdownbase"; import { MatrixDropdownColumn } from "../src/question_matrixdropdowncolumn"; @@ -1550,3 +1550,50 @@ QUnit.test("choices property visibility, Bug#8560", function (assert) { matrix.cellType = "comment"; assert.equal(prop.isVisible("", matrix), false, "#4"); }); +QUnit.test("Column total properties visibility, Bug#8581", function (assert) { + const survey = new SurveyModel({ + elements: [ + { + type: "matrixdynamic", + name: "matrix", + columns: [ + { cellType: "checkbox", name: "col1" } + ] + } + ] + }); + const matrix = survey.getQuestionByName("matrix"); + const column = matrix.columns[0]; + const isPropVisible = (name: string): boolean => { + const prop = Serializer.findProperty("matrixdropdowncolumn", name); + return prop.isVisible("", column); + }; + const checkPropsVisibility = (names: Array, val: boolean, num: number): void => { + names.forEach(name => { + assert.equal(isPropVisible(name), val, name + " #" + num.toString()); + }); + }; + const totalsNames = ["totalType", "totalExpression"]; + const totalsDispNames = ["totalFormat", "totalDisplayStyle", "totalAlignment", "totalCurrency", + "totalMaximumFractionDigits", "totalMinimumFractionDigits"]; + checkPropsVisibility(totalsNames, true, 1); + checkPropsVisibility(totalsDispNames, false, 1); + column.totalExpression = "countInArray({matrix}, 'col1')"; + checkPropsVisibility(totalsNames, true, 2); + checkPropsVisibility(totalsDispNames, true, 2); + column.totalExpression = ""; + checkPropsVisibility(totalsNames, true, 3); + checkPropsVisibility(totalsDispNames, false, 3); + column.totalType = "count"; + checkPropsVisibility(totalsNames, true, 4); + checkPropsVisibility(totalsDispNames, true, 4); + column.totalType = "none"; + checkPropsVisibility(totalsNames, true, 5); + checkPropsVisibility(totalsDispNames, false, 5); + column.showInMultipleColumns = true; + checkPropsVisibility(totalsNames, false, 6); + checkPropsVisibility(totalsDispNames, false, 6); + column.showInMultipleColumns = false; + checkPropsVisibility(totalsNames, true, 7); + checkPropsVisibility(totalsDispNames, false, 7); +});