Skip to content

Commit

Permalink
Panel dynamic addConditionObjectsByContext function doesn't work corr…
Browse files Browse the repository at this point in the history
…ectly for a question in the nested panel dynamic fix #8186 (#8187)
  • Loading branch information
andrewtelnov authored Apr 26, 2024
1 parent c4f95d3 commit 6dba512
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1610,11 +1610,15 @@ export class QuestionPanelDynamicModel extends Question
const prefixName = this.getValueName() + indexStr;
const prefixText = this.processedTitle + indexStr;
for (var i = 0; i < panelObjs.length; i++) {
objects.push({
name: prefixName + panelObjs[i].name,
text: prefixText + panelObjs[i].text,
question: panelObjs[i].question,
});
if(!!panelObjs[i].context) {
objects.push(panelObjs[i]);
} else {
objects.push({
name: prefixName + panelObjs[i].name,
text: prefixText + panelObjs[i].text,
question: panelObjs[i].question,
});
}
}
}
if (hasContext) {
Expand All @@ -1627,9 +1631,7 @@ export class QuestionPanelDynamicModel extends Question
text: prefixText + QuestionPanelDynamicItem.ItemVariableName + "." + panelObjs[i].text,
question: panelObjs[i].question
};
if (context === true) {
obj.context = this;
}
obj.context = this;
objects.push(obj);
}
}
Expand Down
54 changes: 53 additions & 1 deletion tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Question } from "../src/question";
import { Question, IConditionObject } from "../src/question";
import { PanelModel } from "../src/panel";
import { QuestionPanelDynamicModel } from "../src/question_paneldynamic";
import { SurveyModel } from "../src/survey";
Expand Down Expand Up @@ -1621,11 +1621,13 @@ QUnit.test("panelDynamic.addConditionObjectsByContext", function(assert) {
name: "panel.q2.item1",
text: "panel.Question 2.item1",
question: "q2",
context: "qPanel"
},
{
name: "panel.q2.item2",
text: "panel.Question 2.item2",
question: "q2",
context: "qPanel"
},
],
"addConditionObjectsByContext work correctly for panel dynamic with context"
Expand Down Expand Up @@ -1697,11 +1699,13 @@ QUnit.test("panelDynamic.addConditionObjectsByContext + settings.panelDynamicMax
name: "panel.q2.item1",
text: "panel.Question 2.item1",
question: "q2",
context: "qPanel"
},
{
name: "panel.q2.item2",
text: "panel.Question 2.item2",
question: "q2",
context: "qPanel"
},
],
"addConditionObjectsByContext work correctly for panel dynamic with context"
Expand Down Expand Up @@ -1770,11 +1774,13 @@ QUnit.test("panelDynamic.addConditionObjectsByContext + settings.panelDynamicMax
name: "panel.q2.item1",
text: "panel.Question 2.item1",
question: "q2",
context: "qPanel"
},
{
name: "panel.q2.item2",
text: "panel.Question 2.item2",
question: "q2",
context: "qPanel"
},
],
"addConditionObjectsByContext work correctly for panel dynamic with context"
Expand Down Expand Up @@ -1807,6 +1813,52 @@ QUnit.test("panelDynamic.addConditionObjectsByContext + settings.panelDynamicMax
);
settings.panelDynamicMaxPanelCountInCondition = 1;
});
QUnit.test("panelDynamic.addConditionObjectsByContext + nested dynamic panel + context", function(assert) {
const survey = new SurveyModel({
"elements": [
{
"type": "paneldynamic",
"name": "question1",
"title": "parent dynamic panel",
"templateElements": [
{
"type": "paneldynamic",
"name": "question2",
"title": "nested dynamic panel",
"templateElements": [
{
"type": "text",
"name": "question3",
"title": "nq1"
},
{
"type": "text",
"name": "question4",
"title": "nq2"
}
]
},
{
"type": "text",
"name": "question5",
"title": "pq1"
}
]
}
]
});
const rootPanel = survey.getQuestionByName("question1");
const nestedPanel = rootPanel.template.getQuestionByName("question2");
const question3 = nestedPanel.template.getQuestionByName("question3");
const objs: IConditionObject[] = [];
rootPanel.addConditionObjectsByContext(objs, question3);
assert.equal(objs.length, 4, "There should be 4 elements");
assert.equal(objs[0].name, "question1[0].question2[0].question3", "value #0");
assert.equal(objs[1].name, "question1[0].question2[0].question4", "value #1");
assert.equal(objs[2].name, "panel.question4", "value #2");
assert.equal(objs[2].text, "panel.nq2", "text #2");
assert.equal(objs[3].name, "question1[0].question5", "value #3");
});

QUnit.test("matrixDynamic.getConditionJson", function(assert) {
var panel = new QuestionPanelDynamicModel("panel");
Expand Down

0 comments on commit 6dba512

Please sign in to comment.