Skip to content

Commit

Permalink
The Next button does not appear when navigating back in a survey and …
Browse files Browse the repository at this point in the history
…the Complete Trigger was executed fix #6970
  • Loading branch information
andrewtelnov committed Sep 18, 2023
1 parent 964e63d commit f2579aa
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4371,23 +4371,30 @@ export class SurveyModel extends SurveyElementCore
const prevCanBeCompleted = this.canBeCompletedByTrigger;
if(!this.completedByTriggers) this.completedByTriggers = {};
if(isCompleted) {
this.completedByTriggers[trigger.id] = trigger;
this.completedByTriggers[trigger.id] = { trigger: trigger, pageId: this.currentPage?.id };
} else {
delete this.completedByTriggers[trigger.id];
}
if(prevCanBeCompleted !== this.canBeCompletedByTrigger) {
this.updateButtonsVisibility();
}
}
private completedByTriggers: HashTable<Trigger>;
private completedByTriggers: HashTable<any>;
private get canBeCompletedByTrigger(): boolean {
if(!this.completedByTriggers) return false;
return Object.keys(this.completedByTriggers).length > 0;
const keys = Object.keys(this.completedByTriggers);
if(keys.length === 0) return false;
const id = this.currentPage?.id;
if(!id) return true;
for(let i = 0; i < keys.length; i ++) {
if(id === this.completedByTriggers[keys[i]].pageId) return true;
}
return false;
}
private get completedTrigger(): Trigger {
if(!this.canBeCompletedByTrigger) return undefined;
const key = Object.keys(this.completedByTriggers)[0];
return this.completedByTriggers[key];
return this.completedByTriggers[key].trigger;
}
/**
* Returns HTML content displayed on the [complete page](https://surveyjs.io/form-library/documentation/design-survey/create-a-multi-page-survey#complete-page).
Expand Down
51 changes: 51 additions & 0 deletions tests/surveytriggertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,55 @@ QUnit.test("complete trigger for showOtherItem, Bug#6792", function (assert) {
assert.equal(survey.currentPageNo, 0, "We are staying on the same page");
assert.equal(survey.state, "running", "Survey is not completed");
settings.triggers.executeCompleteOnValueChanged = oldSettings;
});
QUnit.test("complete trigger and next/complete buttons, Bug#6970", function (assert) {
const survey = new SurveyModel({
"pages": [
{
"name": "page1",
"elements": [
{
"type": "text",
"name": "question1"
}
]
},
{
"name": "page2",
"elements": [
{
"type": "text",
"name": "question2"
}
]
},
{
"name": "page3",
"elements": [
{
"type": "text",
"name": "question3"
}
]
}
],
"triggers": [
{
"type": "complete",
"expression": "{question2} notempty"
}
] });
const q2 = survey.getQuestionByName("question2");
survey.nextPage();
assert.equal(survey.isCompleteButtonVisible, false, "complete button is invisible, #1");
assert.equal(survey.isShowNextButton, true, "next button is visible, #1");
q2.value = "a";
assert.equal(survey.isCompleteButtonVisible, true, "complete button is visible, #2");
assert.equal(survey.isShowNextButton, false, "next button is invisible, #2");
survey.prevPage();
assert.equal(survey.isCompleteButtonVisible, false, "complete button is invisible, #3");
assert.equal(survey.isShowNextButton, true, "next button is visible, #3");
survey.nextPage();
assert.equal(survey.isCompleteButtonVisible, true, "complete button is visible, #4");
assert.equal(survey.isShowNextButton, false, "next button is invisible, #4");
});

0 comments on commit f2579aa

Please sign in to comment.