Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: onCompleting event doesn't work correctly in preview mode. #3157 #3158

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3340,10 +3340,9 @@ export class SurveyModel extends Base
if (this.doServerValidation(doComplete)) return false;
if (doComplete) {
this.currentPage.passed = true;
this.doComplete();
} else {
this.doNextPage();
return this.doComplete();
}
this.doNextPage();
return true;
}
/**
Expand Down Expand Up @@ -3558,9 +3557,11 @@ export class SurveyModel extends Base
* - calls `sendResult` function.
*
* Calling the `doComplete` function does not perform any validation, unlike the `completeLastPage` function.
* The function can return false, if you set options.allowComplete to false in onCompleting event. Otherwise it returns true.
* It calls `navigateToUrl` after calling `onComplete` event.
* In case calling `options.showDataSaving` callback in the `onComplete` event, `navigateToUrl` is used on calling `options.showDataSavingSuccess` callback.
* @see completeLastPage
* @see onCompleting
* @see cookieName
* @see state
* @see onComplete
Expand All @@ -3569,13 +3570,13 @@ export class SurveyModel extends Base
* @see navigateToUrl
* @see navigateToUrlOnCondition
*/
public doComplete(isCompleteOnTrigger: boolean = false) {
public doComplete(isCompleteOnTrigger: boolean = false): boolean {
var onCompletingOptions = {
allowComplete: true,
isCompleteOnTrigger: isCompleteOnTrigger,
};
this.onCompleting.fire(this, onCompletingOptions);
if (!onCompletingOptions.allowComplete) return;
if (!onCompletingOptions.allowComplete) return false;
let previousCookie = this.hasCookie;
this.stopTimer();
this.setCompleted();
Expand Down Expand Up @@ -3607,6 +3608,7 @@ export class SurveyModel extends Base
if (!savingDataStarted) {
this.navigateTo();
}
return true;
}
/**
* Starts the survey. Changes the survey mode from "starting" to "running". Call this function if your survey has a start page, otherwise this function does nothing.
Expand Down
24 changes: 24 additions & 0 deletions tests/surveyShowPreviewTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,30 @@ QUnit.test(
assert.equal(survey.currentPageNo, 1, "Current page is the last one");
}
);
QUnit.test(
"showPreviewBeforeComplete = 'showAllQuestions', and do noting onCompleting, options.allowComplete = false",
function(assert) {
var survey = new SurveyModel({
pages: [
{ elements: [{ type: "text", name: "q1" }] },
{ elements: [{ type: "text", name: "q2" }] },
],
});
survey.showPreviewBeforeComplete = "showAllQuestions";
var allowComplete = false;
survey.onCompleting.add((sender, options) => {
options.allowComplete = allowComplete;
});
survey.currentPageNo = 1;
survey.showPreview();
assert.equal(survey.state, "preview");
survey.completeLastPage();
assert.equal(survey.state, "preview", "Keep showing preview");
allowComplete = true;
survey.completeLastPage();
assert.equal(survey.state, "completed");
}
);

QUnit.test(
"showPreviewBeforeComplete = 'showAllQuestions', questionsOnPageMode = 'singlePage'",
Expand Down