Skip to content

Commit

Permalink
Multi-Select Matrix with a 'showInMultipleColumns' Checkboxes column …
Browse files Browse the repository at this point in the history
…produces a wrong response fix #8348 (#8353)
  • Loading branch information
andrewtelnov authored Jun 3, 2024
1 parent 4b5f8c1 commit 7f6ef9a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/question_matrixdropdowncolumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,13 @@ export class MatrixDropdownColumn extends Base
json[prop] = this.jsonObj[prop];
});
}
if(json["choicesOrder"] === "random") {
json["choicesOrder"] = "none";
const visChoices = this.templateQuestion["visibleChoices"];
if(Array.isArray(visChoices)) {
json["choices"] = visChoices;
}
}

new JsonObject().toObject(json, question);
question.isContentElement = this.templateQuestion.isContentElement;
Expand All @@ -806,8 +813,11 @@ export class MatrixDropdownColumn extends Base
this.updateIsRenderedRequired(newValue);
}
if (!this.colOwner || this.isLoadingFromJson) return;
if (this.isShowInMultipleColumns && ["visibleChoices", "choices"].indexOf(name) > -1) {
this.colOwner.onShowInMultipleColumnsChanged(this);
if (this.isShowInMultipleColumns) {
if(name === "choicesOrder") return;
if(["visibleChoices", "choices"].indexOf(name) > -1) {
this.colOwner.onShowInMultipleColumnsChanged(this);
}
}
if (!Serializer.hasOriginalProperty(this, name)) return;
this.colOwner.onColumnPropertyChanged(this, name, newValue);
Expand Down
42 changes: 41 additions & 1 deletion tests/question_matrixdropdownbasetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Serializer } from "../src/jsonobject";
import { QuestionDropdownModel } from "../src/question_dropdown";
import { QuestionMatrixDropdownModelBase } from "../src/question_matrixdropdownbase";
import { MatrixDropdownColumn } from "../src/question_matrixdropdowncolumn";
import { QuestionMatrixDynamicModel } from "../src/question_matrixdynamic";
import { MatrixDynamicRowModel, QuestionMatrixDynamicModel } from "../src/question_matrixdynamic";
import { QuestionTagboxModel } from "../src/question_tagbox";
import { SurveyModel } from "../src/survey";
import { Helpers } from "../src/helpers";
export * from "../src/localization/german";

export default QUnit.module("Survey_QuestionMatrixDropdownBase");
Expand Down Expand Up @@ -1344,4 +1345,43 @@ QUnit.test("defaultValueExpression & using rowvalue in it", function (assert) {
assert.equal(matrix.visibleRows[0].cells[1].question.value, 12, "Keep value in the standard cell");
assert.equal(matrix.visibleRows[0].cells[0].question.value, 30, "cell1 value #3");
assert.equal(matrix.visibleRows[1].cells[0].question.value, 50, "cell1 value #3");
});
QUnit.test("showInMultipleColumns & random choices, Bug#8348", function (assert) {
let index = 0;
class HelpTest {
public static randomizeArray<T>(array: Array<T>): Array<T> {
if (array.length < 2) return array;
const el0 = array[index];
array.splice(0, 1, array[array.length - index - 1]);
array.splice(array.length - index - 1, 1, el0);
index = (index + 1) % array.length;
return array;
}
}
const oldFunc = Helpers.randomizeArray;
Helpers.randomizeArray = HelpTest.randomizeArray;
const survey = new SurveyModel({
elements: [
{
"type": "matrixdropdown",
"name": "matrix",
"columns": [
{
"name": "column",
"cellType": "radiogroup",
"showInMultipleColumns": true,
"choices": ["col1", "col2", "col3", "col4", "col5"],
"choicesOrder": "random"
}
],
"rows": ["row1", "row2"]
}
]
});
const matrix = <QuestionMatrixDynamicModel>survey.getQuestionByName("matrix");
const rows = matrix.renderedTable.rows;
assert.equal(matrix.columns[0].templateQuestion.visibleChoices[0].value, "col5", "column tempate");
assert.equal(rows[0].cells[1].question.visibleChoices[0].value, "col5", "row1 question");
assert.equal(rows[1].cells[1].question.visibleChoices[0].value, "col5", "row2 question");
Helpers.randomizeArray = oldFunc;
});
2 changes: 1 addition & 1 deletion tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7507,7 +7507,7 @@ QUnit.test("Questions are randomized", function (assert) {

class HelpTest {
public static randomizeArray<T>(array: Array<T>): Array<T> {
if (array.length < 2) return;
if (array.length < 2) return array;
const el0 = array[0];
array.splice(0, 1, array[array.length - 1]);
array.splice(array.length - 1, 1, el0);
Expand Down

0 comments on commit 7f6ef9a

Please sign in to comment.