Skip to content

Commit

Permalink
Question Numbers may not appear initially at Design Time for panel dy…
Browse files Browse the repository at this point in the history
…namic questions fix #8793 (#8794)
  • Loading branch information
andrewtelnov authored Sep 9, 2024
1 parent 766c65d commit f8fa6af
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
11 changes: 4 additions & 7 deletions packages/survey-core/src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,13 +1288,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;
}
Expand Down
39 changes: 38 additions & 1 deletion packages/survey-core/tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <QuestionPanelDynamicModel>survey.getQuestionByName("panel");
const q2 = <Question>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");
Expand Down

0 comments on commit f8fa6af

Please sign in to comment.