Skip to content

Commit

Permalink
The survey.onValidatedErrorsOnCurrentPage function is not raised when…
Browse files Browse the repository at this point in the history
… a user attempts to navigate to another page using Table Of Contens when a page contains validation errors fix #9241 (#9246)
  • Loading branch information
andrewtelnov authored Jan 3, 2025
1 parent 52b1df8 commit c198254
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3427,7 +3427,8 @@ export class SurveyModel extends SurveyElementCore
this.currentPageNo = index;
return true;
}
for (let i = this.currentPageNo; i < index; i++) {
if(!this.validateCurrentPage()) return false;
for (let i = this.currentPageNo + 1; i < index; i++) {
const page = this.visiblePages[i];
if (!page.validate(true, true)) return false;
page.passed = true;
Expand Down
62 changes: 61 additions & 1 deletion packages/survey-core/tests/surveyTOCTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,64 @@ QUnit.test("survey.tryNavigateToPage respects validationAllowSwitchPages and val
assert.equal(survey.currentPageNo, 0, "currentPageNo #1");
assert.equal(survey.tryNavigateToPage(survey.pages[1]), true, "navigate #9");
assert.equal(survey.currentPageNo, 1, "currentPageNo #2");
});
});
QUnit.test("survey.tryNavigateToPage & survey.onValidatedErrorsOnCurrentPage, Bug#9241", function (assert) {
let json: any = {
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1",
"isRequired": true
}
]
},
{
"name": "page2",
"elements": [
{
"type": "text",
"name": "question2",
"isRequired": true
}
]
},
{
"name": "page3",
"elements": [
{
"type": "text",
"name": "question3",
"isRequired": true
}
]
}
]
};
const survey = new SurveyModel(json);
const logs = new Array<string>();
survey.onValidatedErrorsOnCurrentPage.add((sender, options) => {
logs.push(options.page.name);
});
assert.equal(survey.tryNavigateToPage(survey.pages[1]), false, "try #1");
assert.deepEqual(logs, ["page1"], "logs #1");
survey.setValue("question1", "val1");
assert.equal(survey.tryNavigateToPage(survey.pages[1]), true, "try #2");
assert.deepEqual(logs, ["page1", "page1"], "logs #2");
assert.equal(survey.tryNavigateToPage(survey.pages[0]), true, "try #3");
assert.deepEqual(logs, ["page1", "page1"], "logs #3");
assert.equal(survey.tryNavigateToPage(survey.pages[2]), false, "try #4");
assert.equal(survey.currentPageNo, 1, "currentPageNo #4");
assert.deepEqual(logs, ["page1", "page1", "page1"], "logs #4");
assert.equal(survey.tryNavigateToPage(survey.pages[1]), false, "try #5");
assert.deepEqual(logs, ["page1", "page1", "page1"], "logs #5");
assert.equal(survey.tryNavigateToPage(survey.pages[2]), false, "try #6");
assert.deepEqual(logs, ["page1", "page1", "page1", "page2"], "logs #6");
survey.setValue("question2", "val2");
assert.equal(survey.tryNavigateToPage(survey.pages[2]), true, "try #7");
assert.deepEqual(logs, ["page1", "page1", "page1", "page2", "page2"], "logs #7");
assert.equal(survey.tryNavigateToPage(survey.pages[0]), true, "try #8");
assert.deepEqual(logs, ["page1", "page1", "page1", "page2", "page2"], "logs #8");
});

0 comments on commit c198254

Please sign in to comment.