diff --git a/README.md b/README.md index be190bdfff..f1beab40b4 100644 --- a/README.md +++ b/README.md @@ -61,10 +61,17 @@ Make sure that you have Node.js v14 or later and a compatible npm version instal npm install ``` +1. **Build the [platform-independent part](https://github.com/surveyjs/survey-library/blob/master/build-scripts/survey-core/README.md#survey-model-platform-independent-part) and plugins** + + ``` + npm run build_core + npm run build-plugins + ``` + 1. **Build the library** ``` - npm run build_prod + npm run build ``` You can find the built scripts and style sheets in folders under the `build` directory. @@ -72,7 +79,7 @@ Make sure that you have Node.js v14 or later and a compatible npm version instal 1. **Run test examples** ``` - npm start + npm run serve ``` This command runs a local HTTP server at http://localhost:7777/. diff --git a/src/question_paneldynamic.ts b/src/question_paneldynamic.ts index 2a236e7914..2ff83036e0 100644 --- a/src/question_paneldynamic.ts +++ b/src/question_paneldynamic.ts @@ -808,9 +808,8 @@ export class QuestionPanelDynamicModel extends Question } } } - let removedPanels:Array = []; if (val < this.panelCount) { - removedPanels = this.panelsCore.splice(val, this.panelCount - val); + this.panelsCore.splice(val, this.panelCount - val); } this.setValueAfterPanelsCreating(); this.setValueBasedOnPanelCount(); @@ -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) { diff --git a/tests/question_paneldynamic_tests.ts b/tests/question_paneldynamic_tests.ts index 6c754acd47..e6e0210997 100644 --- a/tests/question_paneldynamic_tests.ts +++ b/tests/question_paneldynamic_tests.ts @@ -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 = 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"); +});