Skip to content

Commit

Permalink
Multi-Select Matrix - The column total doesn't calculate the actual v…
Browse files Browse the repository at this point in the history
…alue for a column which has 'showInMultipleColumns: true' fix #8581
  • Loading branch information
andrewtelnov committed Jul 25, 2024
1 parent d1122f2 commit dee96e8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/question_matrixdropdowncolumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
49 changes: 48 additions & 1 deletion tests/question_matrixdropdownbasetests.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix");
const column = <MatrixDropdownColumn>matrix.columns[0];
const isPropVisible = (name: string): boolean => {
const prop = Serializer.findProperty("matrixdropdowncolumn", name);
return prop.isVisible("", column);
};
const checkPropsVisibility = (names: Array<string>, 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);
});

0 comments on commit dee96e8

Please sign in to comment.