Skip to content

Commit

Permalink
checkErrorsMode = "onComplete" - A survey validates questions when us…
Browse files Browse the repository at this point in the history
…ers click Preview rather than when they complete the survey fix #6608 (#6638)
  • Loading branch information
andrewtelnov committed Aug 3, 2023
1 parent ebf943b commit 6aea5c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3810,8 +3810,10 @@ export class SurveyModel extends SurveyElementCore
*/
public showPreview(): boolean {
this.resetNavigationButton();
if (this.hasErrorsOnNavigate(true)) return false;
if (this.doServerValidation(true, true)) return false;
if (this.checkErrorsMode !== "onComplete") {
if (this.hasErrorsOnNavigate(true)) return false;
if (this.doServerValidation(true, true)) return false;
}
this.showPreviewCore();
return true;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/surveyShowPreviewTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SurveyModel } from "../src/survey";
import { surveyLocalization } from "../src/surveyStrings";
import { PanelModel } from "../src/panel";
import { StylesManager } from "../src/stylesmanager";
import { settings } from "../src/settings";

export default QUnit.module("SurveyShowPreviewTests");

Expand Down Expand Up @@ -732,3 +733,20 @@ QUnit.test(
assert.equal(survey.getAllQuestions(true).length, 2, "Show all questions");
}
);
QUnit.test("showPreviewBeforeComplete = 'showAnsweredQuestions' and all questions are empty, bug#6608",
function(assert) {
const survey = new SurveyModel({
"elements": [{ "type": "text", "name": "q1", "isRequired": true }],
"showPreviewBeforeComplete": "showAnsweredQuestions"
});
survey.showPreview();
assert.equal(survey.state, "running", "There is an error");
survey.checkErrorsMode = "onComplete";
survey.showPreview();
assert.equal(survey.state, "preview", "We do not check for errors");
survey.cancelPreview();
assert.equal(survey.state, "running", "running again");
survey.completeLastPage();
assert.equal(survey.state, "running", "We have errors, we can't fix errors");
}
);

0 comments on commit 6aea5c9

Please sign in to comment.