diff --git a/packages/survey-core/src/question_paneldynamic.ts b/packages/survey-core/src/question_paneldynamic.ts index 9ab9baa417..1abe92c3cc 100644 --- a/packages/survey-core/src/question_paneldynamic.ts +++ b/packages/survey-core/src/question_paneldynamic.ts @@ -1281,13 +1281,10 @@ export class QuestionPanelDynamicModel extends Question public setVisibleIndex(value: number): number { if (!this.isVisible) return 0; const onSurveyNumbering = this.showQuestionNumbers === "onSurvey"; - var startIndex = onSurveyNumbering ? value : 0; - for (var i = 0; i < this.visiblePanelsCore.length; i++) { - var counter = this.setPanelVisibleIndex( - this.visiblePanelsCore[i], - startIndex, - this.showQuestionNumbers != "off" - ); + let startIndex = onSurveyNumbering ? value : 0; + const panels = this.isDesignMode ? [this.template] : this.visiblePanelsCore; + for (let i = 0; i < panels.length; i++) { + let counter = this.setPanelVisibleIndex(panels[i], startIndex, this.showQuestionNumbers != "off"); if (onSurveyNumbering) { startIndex += counter; } diff --git a/packages/survey-core/tests/question_paneldynamic_tests.ts b/packages/survey-core/tests/question_paneldynamic_tests.ts index d11e0850ab..6dda03a859 100644 --- a/packages/survey-core/tests/question_paneldynamic_tests.ts +++ b/packages/survey-core/tests/question_paneldynamic_tests.ts @@ -915,7 +915,44 @@ QUnit.test("PanelDynamic, question no", function(assert) { assert.equal(question2.visibleIndex, 2, "onSurvey, second panel is removed - question2.visibleIndex" ); }); - +QUnit.test("PanelDynamic, showQuestionNumbers onSurvey & design time ", function(assert) { + const survey = new SurveyModel(); + survey.setDesignMode(true); + survey.fromJSON({ + "pages": [ + { + "name": "page1", + "elements": [ + { + "type": "text", + "name": "q1" + } + ] + }, + { + "name": "page2", + "elements": [ + { + "type": "paneldynamic", + "name": "panel", + "templateElements": [ + { + "type": "text", + "name": "q2" + } + ], + "showQuestionNumbers": "onSurvey" + } + ] + } + ] + }); + const q1 = survey.getQuestionByName("q1"); + const panel = survey.getQuestionByName("panel"); + const q2 = panel.templateElements[0]; + assert.equal(q1.no, "1.", "The number should be 1."); + assert.equal(q2.no, "2.", "The number should be 2."); +}); QUnit.test("PanelDynamic, renderMode", function(assert) { var survey = new SurveyModel(); var page = survey.addNewPage("p");