Skip to content

Commit

Permalink
The survey.prevPage() and survey.nextPage() function doesn't correctl…
Browse files Browse the repository at this point in the history
…y navigate to the previous and next pages when a survey displays each question on a separate page fix #9330 (#9392)
  • Loading branch information
andrewtelnov authored Feb 4, 2025
1 parent d040ff8 commit 69f0bf6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4104,6 +4104,7 @@ export class SurveyModel extends SurveyElementCore
* @see completeLastPage
*/
public nextPage(): boolean {
if(this.currentSingleQuestion) return this.performNext();
if (this.isLastPage) return false;
return this.doCurrentPageComplete(false);
}
Expand Down Expand Up @@ -4429,6 +4430,7 @@ export class SurveyModel extends SurveyElementCore
* @see nextPage
*/
public prevPage(): boolean {
if(this.currentSingleQuestion) return this.performPrevious();
if (this.isFirstPage || this.state === "starting") return false;
this.resetNavigationButton();

Expand Down
22 changes: 22 additions & 0 deletions packages/survey-core/tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7835,6 +7835,28 @@ QUnit.test("Randomize questions in page and panels & single question per page",

Helpers.randomizeArray = oldFunc;
});
QUnit.test("questionPerPage vs nextPage&prevPage", function (assert) {
const survey = new SurveyModel({
questionsOnPageMode: "questionPerPage",
pages: [
{ elements: [{ type: "text", name: "q1" }, { type: "text", name: "q2" }] },
{ elements: [{ type: "text", name: "q3" }, { type: "text", name: "q4" }] },
]
});
assert.equal(survey.currentSingleQuestion.name, "q1", "currentSingleQuestion #1");
survey.nextPage();
assert.equal(survey.currentSingleQuestion.name, "q2", "currentSingleQuestion #2");
survey.nextPage();
assert.equal(survey.currentSingleQuestion.name, "q3", "currentSingleQuestion #3");
survey.nextPage();
assert.equal(survey.currentSingleQuestion.name, "q4", "currentSingleQuestion #4");
survey.prevPage();
assert.equal(survey.currentSingleQuestion.name, "q3", "currentSingleQuestion #5");
survey.prevPage();
assert.equal(survey.currentSingleQuestion.name, "q2", "currentSingleQuestion #6");
survey.prevPage();
assert.equal(survey.currentSingleQuestion.name, "q1", "currentSingleQuestion #7");
});

QUnit.test("Quiz, correct, incorrect answers", function (assert) {
var survey = new SurveyModel({
Expand Down

0 comments on commit 69f0bf6

Please sign in to comment.