Skip to content

Commit

Permalink
Merge pull request #9184 from surveyjs/tsv2013/issue9177
Browse files Browse the repository at this point in the history
Table Of Contents - Impossible to switch pages when `validationAllowComplete` and `validationAllowSwitchPages` are enabled
  • Loading branch information
OlgaLarina authored Dec 19, 2024
2 parents 0992744 + ce992bc commit 3c323b0
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3390,7 +3390,7 @@ export class SurveyModel extends SurveyElementCore
const index = this.visiblePages.indexOf(page);
if (index < 0 || index >= this.visiblePageCount) return false;
if (index === this.currentPageNo) return false;
if (index < this.currentPageNo || this.isValidateOnComplete) {
if (index < this.currentPageNo || this.checkErrorsMode === "onComplete" || this.validationAllowSwitchPages) {
this.currentPageNo = index;
return true;
}
Expand Down
74 changes: 74 additions & 0 deletions packages/survey-core/tests/surveyTOCTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,78 @@ QUnit.test("TOC navigation shows page numbers", function (assert) {
assert.equal(tocListModel.actions.length, 1);
assert.equal(tocListModel.actions[0].visible, true);
assert.equal(tocListModel.actions[0].title, "1. page1");
});

QUnit.test("survey.tryNavigateToPage respects validationAllowSwitchPages and validationAllowComplete", function (assert) {
let json: any = {
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1"
}
]
},
{
"name": "page2",
"elements": [
{
"type": "text",
"name": "question2",
"isRequired": true,
"requiredErrorText": "You SSN must be a 9-digit number.",
"validators": [
{
"type": "regex",
"text": "Your SSN must be a 9-digit number",
"regex": "^(?!0{3})(?!6{3})[0-8]\\d{2}-?(?!0{2})\\d{2}-?(?!0{4})\\d{4}$"
}
],
"maxLength": 9
}
]
},
{
"name": "page3",
"elements": [
{
"type": "text",
"name": "question3",
}
]
},
]
};
const survey = new SurveyModel(json);
assert.equal(survey.validationAllowSwitchPages, false);
assert.equal(survey.validationAllowComplete, false);
assert.equal(survey.currentPageNo, 0, "currentPageNo #1");
assert.equal(survey.tryNavigateToPage(survey.pages[2]), false, "navigate #1");
assert.equal(survey.currentPageNo, 1, "currentPageNo #2");
assert.equal(survey.tryNavigateToPage(survey.pages[0]), true, "navigate #2");
assert.equal(survey.currentPageNo, 0, "currentPageNo #1");
assert.equal(survey.tryNavigateToPage(survey.pages[1]), true, "navigate #3");
assert.equal(survey.currentPageNo, 1, "currentPageNo #1");

survey.validationAllowSwitchPages = true;
assert.equal(survey.validationAllowSwitchPages, true);
assert.equal(survey.validationAllowComplete, false);
assert.equal(survey.tryNavigateToPage(survey.pages[2]), true, "navigate #4");
assert.equal(survey.currentPageNo, 2, "currentPageNo #3");
assert.equal(survey.tryNavigateToPage(survey.pages[0]), true, "navigate #5");
assert.equal(survey.currentPageNo, 0, "currentPageNo #1");
assert.equal(survey.tryNavigateToPage(survey.pages[1]), true, "navigate #6");
assert.equal(survey.currentPageNo, 1, "currentPageNo #2");

survey.validationAllowComplete = true;
assert.equal(survey.validationAllowSwitchPages, true);
assert.equal(survey.validationAllowComplete, true);
assert.equal(survey.tryNavigateToPage(survey.pages[2]), true, "navigate #7");
assert.equal(survey.currentPageNo, 2, "currentPageNo #3");
assert.equal(survey.tryNavigateToPage(survey.pages[0]), true, "navigate #8");
assert.equal(survey.currentPageNo, 0, "currentPageNo #1");
assert.equal(survey.tryNavigateToPage(survey.pages[1]), true, "navigate #9");
assert.equal(survey.currentPageNo, 1, "currentPageNo #2");
});

0 comments on commit 3c323b0

Please sign in to comment.