diff --git a/src/question_matrixdropdownbase.ts b/src/question_matrixdropdownbase.ts index 5352fe8b93..9ecc7b1c6c 100644 --- a/src/question_matrixdropdownbase.ts +++ b/src/question_matrixdropdownbase.ts @@ -1392,29 +1392,34 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel= 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(); }); } @@ -1838,7 +1843,11 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel, context: any): void { - const hasColumnContext = !!context && this.columns.indexOf(context) > -1; + let rowElements: Array = [].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) { @@ -1853,12 +1862,12 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel): void { +function updateObjsQuestions(objs: Array, 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; } @@ -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, [ @@ -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, [ @@ -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, [ @@ -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 = [];