Skip to content

Commit

Permalink
Fix the issue with checking error after preview #6608 (#6691)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 10, 2023
1 parent 3433fce commit 36d3a48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3461,7 +3461,7 @@ export class SurveyModel extends SurveyElementCore
this.doCurrentPageCompleteCore(doComplete);
}
};
if (this.checkErrorsMode === "onComplete") {
if (this.isValidateOnComplete) {
if (!this.isLastPage) return false;
return this.validate(true, true, func) !== true;
}
Expand Down Expand Up @@ -3777,7 +3777,10 @@ export class SurveyModel extends SurveyElementCore
* @see nextPage
*/
public completeLastPage(): boolean {
var res = this.doCurrentPageComplete(true);
if(this.isValidateOnComplete) {
this.cancelPreview();
}
let res = this.doCurrentPageComplete(true);
if (res) {
this.cancelPreview();
}
Expand Down Expand Up @@ -3810,7 +3813,7 @@ export class SurveyModel extends SurveyElementCore
*/
public showPreview(): boolean {
this.resetNavigationButton();
if (this.checkErrorsMode !== "onComplete") {
if (!this.isValidateOnComplete) {
if (this.hasErrorsOnNavigate(true)) return false;
if (this.doServerValidation(true, true)) return false;
}
Expand Down Expand Up @@ -4253,7 +4256,7 @@ export class SurveyModel extends SurveyElementCore
self.completeServerValidation(options, isPreview);
},
};
if (doComplete && this.checkErrorsMode === "onComplete") {
if (doComplete && this.isValidateOnComplete) {
options.data = this.data;
} else {
var questions = this.activePage.questions;
Expand All @@ -4277,7 +4280,7 @@ export class SurveyModel extends SurveyElementCore
(<EventBase<SurveyModel>>this.onServerValidateQuestions).isEmpty
)
return false;
if (!doComplete && this.checkErrorsMode === "onComplete") return false;
if (!doComplete && this.isValidateOnComplete) return false;
this.setIsValidatingOnServer(true);
const isFunc = typeof this.onServerValidateQuestions === "function";
this.serverValidationEventCount = !isFunc ? this.onServerValidateQuestions.length : 1;
Expand Down Expand Up @@ -4713,6 +4716,9 @@ export class SurveyModel extends SurveyElementCore
get isValidateOnValueChanged(): boolean {
return this.checkErrorsMode === "onValueChanged";
}
private get isValidateOnComplete(): boolean {
return this.checkErrorsMode === "onComplete";
}
matrixCellValidate(question: QuestionMatrixDropdownModelBase, options: MatrixCellValidateEvent): SurveyError {
options.question = question;
this.onMatrixCellValidate.fire(this, options);
Expand Down Expand Up @@ -5312,7 +5318,7 @@ export class SurveyModel extends SurveyElementCore
private checkQuestionErrorOnValueChanged(question: Question) {
if (
!this.isNavigationButtonPressed &&
(this.checkErrorsMode === "onValueChanged" ||
(this.isValidateOnValueChanged ||
question.getAllErrors().length > 0)
) {
this.checkQuestionErrorOnValueChangedCore(question);
Expand Down
22 changes: 22 additions & 0 deletions tests/surveyShowPreviewTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -748,5 +748,27 @@ QUnit.test("showPreviewBeforeComplete = 'showAnsweredQuestions' and all question
assert.equal(survey.state, "running", "running again");
survey.completeLastPage();
assert.equal(survey.state, "running", "We have errors, we can't fix errors");
survey.setValue("q1", "a");
survey.completeLastPage();
assert.equal(survey.state, "completed", "No errors");
}
);
QUnit.test("showPreviewBeforeComplete = 'showAnsweredQuestions' & checkErrorsMode = 'onComplete' and all questions are empty, bug#6608",
function(assert) {
const survey = new SurveyModel({
"pages": [
{ "elements": [{ "type": "text", "name": "q1", "isRequired": true }] },
{ "elements": [{ "type": "text", "name": "q2" }] },
],
"showPreviewBeforeComplete": "showAnsweredQuestions",
"checkErrorsMode": "onComplete"
});
survey.nextPage();
survey.showPreview();
survey.completeLastPage();
assert.equal(survey.state, "running", "We have errors, we can't fix errors");
survey.setValue("q1", "a");
survey.completeLastPage();
assert.equal(survey.state, "completed", "No errors");
}
);

0 comments on commit 36d3a48

Please sign in to comment.