Skip to content

Commit

Permalink
Knockout: Exception related with dynamic panel performance optimization
Browse files Browse the repository at this point in the history
fix #7693 (#7696)
  • Loading branch information
andrewtelnov authored Jan 18, 2024
1 parent f7bfa3b commit ce3e6f7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,8 @@ export class QuestionPanelDynamicModel extends Question
}
}
}
let removedPanels:Array<PanelModel> = [];
if (val < this.panelCount) {
removedPanels = this.panelsCore.splice(val, this.panelCount - val);
this.panelsCore.splice(val, this.panelCount - val);
}
this.setValueAfterPanelsCreating();
this.setValueBasedOnPanelCount();
Expand Down Expand Up @@ -1409,7 +1408,7 @@ export class QuestionPanelDynamicModel extends Question
}
}
public getQuestionFromArray(name: string, index: number): IQuestion {
if (index >= this.panelCount) return null;
if (index < 0 || index >= this.panelsCore.length) return null;
return this.panelsCore[index].getQuestionByName(name);
}
private clearIncorrectValuesInPanel(index: number) {
Expand Down
49 changes: 49 additions & 0 deletions tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6628,3 +6628,52 @@ QUnit.test("panel dynamic & dropdown with showOtherItem", function (assert) {
question.comment = "comment2";
assert.deepEqual(dynamicPanel.value, [{ q1: "other", "q1-Comment": "comment2" }], "panel.value #4");
});
QUnit.test("panel dynamic & getQuestionFromArray with non-build panels, #7693", function (assert) {
const survey = new SurveyModel({
pages: [
{ elements: [{ type: "text", name: "q1" }] },
{
elements: [
{
type: "paneldynamic",
name: "panel",
panelCount: 1,
templateElements: [
{ name: "q2", type: "text" }
]
}
]
}
] });
const dynamicPanel = survey.getQuestionByName("panel");
assert.notOk(dynamicPanel.getQuestionFromArray("q2", 0), "Panels are not created yet");
survey.currentPageNo = 1;
assert.equal(dynamicPanel.getQuestionFromArray("q2", 0).name, "q2", "Panels are created");
});
QUnit.test("panel dynamic & addPanel/removePanel with non-build panels, #7693", function (assert) {
const survey = new SurveyModel({
pages: [
{ elements: [{ type: "text", name: "q1" }] },
{
elements: [
{
type: "paneldynamic",
name: "panel",
panelCount: 1,
templateElements: [
{ name: "q2", type: "text" }
]
}
]
}
] });
const dynamicPanel = <QuestionPanelDynamicModel>survey.getQuestionByName("panel");
assert.equal(dynamicPanel.panelCount, 1, "panelCount #1");
assert.notOk(dynamicPanel.getQuestionFromArray("q2", 0), "Panels are not created yet");
dynamicPanel.addPanel();
dynamicPanel.addPanel(1);
assert.equal(dynamicPanel.panelCount, 3, "panelCount #2");
dynamicPanel.removePanel(1);
assert.equal(dynamicPanel.panelCount, 2, "panelCount #3");
assert.equal(dynamicPanel.getQuestionFromArray("q2", 0).name, "q2", "Panels are created");
});

0 comments on commit ce3e6f7

Please sign in to comment.