Skip to content

Commit

Permalink
Dynamic Matrix - Condition Editor doesn't list questions located with…
Browse files Browse the repository at this point in the history
…in a detail section fix #8561
  • Loading branch information
andrewtelnov committed Jul 15, 2024
1 parent 28f888f commit 0460edd
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 21 deletions.
41 changes: 25 additions & 16 deletions src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1392,29 +1392,34 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
}
public getConditionJson(operator: string = null, path: string = null): any {
if (!path) return super.getConditionJson(operator);
var columnName = "";
for (var i = path.length - 1; i >= 0; i--) {
let columnName = "";
for (let i = path.length - 1; i >= 0; i--) {
if (path[i] == ".") break;
columnName = path[i] + columnName;
}
var column = this.getColumnByName(columnName);
if (!column) return null;
var question = column.createCellQuestion(null);
if (!question) return null;
return question.getConditionJson(operator);
let question = undefined;
let column = this.getColumnByName(columnName);
if (!!column) {
question = column.createCellQuestion(null);
} else {
if(this.detailPanelMode !== "none") {
question = this.detailPanel.getQuestionByName(columnName);
}
}
return !!question ? question.getConditionJson(operator) : null;
}
public clearIncorrectValues() {
public clearIncorrectValues(): void {
var rows = this.visibleRows;
if (!rows) return;
for (var i = 0; i < rows.length; i++) {
rows[i].clearIncorrectValues(this.getRowValue(i));
}
}
public clearErrors() {
public clearErrors(): void {
super.clearErrors();
this.runFuncForCellQuestions((q: Question) => { q.clearErrors(); });
}
public localeChanged() {
public localeChanged(): void {
super.localeChanged();
this.runFuncForCellQuestions((q: Question) => { q.localeChanged(); });
}
Expand Down Expand Up @@ -1838,7 +1843,11 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
return questionPlainData;
}
public addConditionObjectsByContext(objects: Array<IConditionObject>, context: any): void {
const hasColumnContext = !!context && this.columns.indexOf(context) > -1;
let rowElements: Array<any> = [].concat(this.columns);
if(this.detailPanelMode !== "none") {
rowElements = rowElements.concat(this.detailPanel.questions);
}
const hasColumnContext = !!context && rowElements.indexOf(context) > -1;
const hasContext = context === true || hasColumnContext;
const rowsIndeces = this.getConditionObjectsRowIndeces();
if (hasContext) {
Expand All @@ -1853,12 +1862,12 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
const dot = hasQuestionPrefix && index === -1 ? "." : "";
const prefixName = (hasQuestionPrefix ? this.getValueName() : "") + dot + rowName + ".";
const prefixTitle = (hasQuestionPrefix ? this.processedTitle : "") + dot + rowText + ".";
for (var j = 0; j < this.columns.length; j++) {
const column = this.columns[j];
if (index === -1 && context === column) continue;
for (var j = 0; j < rowElements.length; j++) {
const rowElement = rowElements[j];
if (index === -1 && context === rowElement) continue;
const obj: IConditionObject = {
name: prefixName + column.name,
text: prefixTitle + column.fullTitle,
name: prefixName + rowElement.name,
text: prefixTitle + rowElement.fullTitle,
question: this
};

Expand Down
73 changes: 68 additions & 5 deletions tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1616,9 +1616,13 @@ QUnit.test(
}
);

function updateObjsQuestions(objs: Array<any>): void {
function updateObjsQuestions(objs: Array<any>, removeQuestion: boolean = false): void {
for (var i = 0; i < objs.length; i++) {
objs[i].question = objs[i].question.name;
if(removeQuestion) {
delete objs[i].question;
} else {
objs[i].question = objs[i].question.name;
}
if (!!objs[i].context) {
objs[i].context = objs[i].context.name;
}
Expand Down Expand Up @@ -1750,7 +1754,7 @@ QUnit.test(
question.title = "Matrix";
question.addColumn("col1", "Column 1");
question.addConditionObjectsByContext(objs, null);
for (var i = 0; i < objs.length; i++) delete objs[i].question;
updateObjsQuestions(objs, true);
assert.deepEqual(
objs,
[
Expand All @@ -1766,7 +1770,7 @@ QUnit.test(

objs = [];
question.addConditionObjectsByContext(objs, null);
for (var i = 0; i < objs.length; i++) delete objs[i].question;
updateObjsQuestions(objs, true);
assert.deepEqual(
objs,
[
Expand All @@ -1780,7 +1784,7 @@ QUnit.test(
question.rowCount = 4;
objs = [];
question.addConditionObjectsByContext(objs, null);
for (var i = 0; i < objs.length; i++) delete objs[i].question;
updateObjsQuestions(objs, true);
assert.deepEqual(
objs,
[
Expand Down Expand Up @@ -1919,6 +1923,65 @@ QUnit.test("matrixDynamic.getConditionJson", function (assert) {
json = question.getConditionJson("contains", "[0].col2");
assert.equal(json.type, "radiogroup", "column 2 get type for contains");
});
QUnit.test("matrixDropdown.addConditionObjectsByContext, detail panel", function (assert) {
var objs = [];
var question = new QuestionMatrixDynamicModel("matrix");
question.title = "Matrix";
question.addColumn("col1", "Column 1");
question.detailPanel.addNewQuestion("text", "q1").title = "Question 1";
question.detailPanelMode = "underRow";
question.addConditionObjectsByContext(objs, null);
updateObjsQuestions(objs, true);
assert.deepEqual(
objs,
[
{
name: "matrix[0].col1",
text: "Matrix[0].Column 1",
},
{
name: "matrix[0].q1",
text: "Matrix[0].Question 1",
},
],
"addConditionObjectsByContext work correctly for matrix dynamic, #1"
);
objs = [];
question.addConditionObjectsByContext(objs, question.columns[0]);
updateObjsQuestions(objs, true);
assert.deepEqual(
objs,
[
{
name: "matrix[0].col1",
text: "Matrix[0].Column 1",
},
{
name: "matrix[0].q1",
text: "Matrix[0].Question 1",
},
{
context: "col1",
name: "row.q1",
text: "row.Question 1",
},
],
"addConditionObjectsByContext work correctly for matrix dynamic, #2"
);
});

QUnit.test("matrixDynamic.getConditionJson, detail panel", function (assert) {
var names = [];
var question = new QuestionMatrixDynamicModel("matrix");
question.addColumn("col1").cellType = "dropdown";
question.addColumn("col2").cellType = "dropdown";
question.detailPanel.addNewQuestion("dropdown", "q1").choices = [1, 2];
question.detailPanelMode = "underRow";
question.rowCount = 2;
var json = question.getConditionJson("equals", "[0].q1");
assert.deepEqual(json.choices, [1, 2], "column 1 get choices");
assert.equal(json.type, "dropdown", "column 1 get type");
});

QUnit.test("matrixDynamic.clearInvisibleValues", function (assert) {
var names = [];
Expand Down

0 comments on commit 0460edd

Please sign in to comment.