Skip to content

Commit

Permalink
onValidatePanel event calls for Page fix #9031 (#9061)
Browse files Browse the repository at this point in the history
* onValidatePanel event calls for Page fix #9031

* FIx errors in visual tests
  • Loading branch information
andrewtelnov authored Nov 18, 2024
1 parent bac2bf9 commit 11ddcc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/survey-core/src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ export class PanelModelBase extends SurveyElement<Question>
private hasErrorsInPanels(rec: any): void {
var errors = <Array<any>>[];
this.hasRequiredError(rec, errors);
if (this.survey) {
if (this.isPanel && this.survey) {
var customError = this.survey.validatePanel(this);
if (customError) {
errors.push(customError);
Expand Down
5 changes: 5 additions & 0 deletions packages/survey-core/tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,9 @@ QUnit.test("onValidatePanel test", function (assert) {
var panel = page.addNewPanel("panel");
var q1 = <QuestionTextModel>panel.addNewQuestion("text", "q1");
var q2 = <QuestionTextModel>panel.addNewQuestion("text", "q2");
let counter = 0;
survey.onValidatePanel.add(function (sender, options) {
counter ++;
var panel = <PanelModel>options.panel;
var pq1 = <QuestionTextModel>panel.getQuestionByName("q1");
var pq2 = <QuestionTextModel>panel.getQuestionByName("q2");
Expand All @@ -2572,20 +2574,23 @@ QUnit.test("onValidatePanel test", function (assert) {
true,
"failed, values are undefined : 10 < q1.value + q2.value < 100"
);
assert.equal(counter, 1, "onValidatePanel calls one time");
q1.value = 5;
q2.value = 50;
assert.equal(
survey.isCurrentPageHasErrors,
false,
"passed: 5 + 50, 10 < q1.value + q2.value < 100"
);
assert.equal(counter, 2, "onValidatePanel calls two time");
q1.value = 55;

assert.equal(
survey.isCurrentPageHasErrors,
true,
"failed: 55 + 50, 10 < q1.value + q2.value < 100"
);
assert.equal(counter, 3, "onValidatePanel calls three time");
});
QUnit.test(
"isCurrentPageHasErrors, required question in the invisible panel, #325",
Expand Down

0 comments on commit 11ddcc9

Please sign in to comment.