Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knockout: Exception related with dynamic panel performance optimizati… #7696

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});
Loading