Skip to content

Commit

Permalink
Fix: onCompleting event doesn't work on "complete" trigger #3184 (#3185)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 10, 2021
1 parent 93b5990 commit f1065a0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3558,7 +3558,10 @@ export class SurveyModel extends Base
isCompleteOnTrigger: isCompleteOnTrigger,
};
this.onCompleting.fire(this, onCompletingOptions);
if (!onCompletingOptions.allowComplete) return false;
if (!onCompletingOptions.allowComplete) {
this.isCompleted = false;
return false;
}
let previousCookie = this.hasCookie;
this.stopTimer();
this.setCompleted();
Expand Down
48 changes: 48 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7475,6 +7475,54 @@ QUnit.test("Compete trigger with invisible question, #2, Bug #2098", function(
survey.nextPage();
assert.equal(survey.state, "completed", "Survey is completed");
});
QUnit.test("Compete trigger and allowComplete false, Bug #3184", function(
assert
) {
var json = {
pages: [
{
elements: [
{
type: "text",
name: "age",
inputType: "number",
},
],
},
{
elements: [
{
type: "text",
name: "question1",
},
],
},
{
elements: [
{
type: "text",
name: "question2",
},
],
},
],
triggers: [
{
type: "complete",
expression: "{age}<18",
},
],
};
var survey = new SurveyModel(json);
survey.onCompleting.add((sender, options) => {
options.allowComplete = false;
});
survey.getQuestionByName("age").value = 10;
assert.equal(survey.currentPageNo, 0);
survey.nextPage();
assert.equal(survey.state, "running", "Survey is not completed");
assert.equal(survey.currentPageNo, 0, "stay on the same page");
});

QUnit.test("textUpdateMode=onTyping and goNextPageAutomatic option", function(
assert
Expand Down

0 comments on commit f1065a0

Please sign in to comment.