Skip to content

Commit

Permalink
Add survey showCompleteButton property fix #7626
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Jan 4, 2024
1 parent 957100c commit f37e605
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,9 @@ export class SurveyModel extends SurveyElementCore
this.registerPropertyChangedHandlers(["renderBackgroundImage", "backgroundOpacity", "backgroundImageFit", "fitToContainer", "backgroundImageAttachment"], () => {
this.updateBackgroundImageStyle();
});
this.registerPropertyChangedHandlers(
["showPrevButton", "showCompleteButton"],
() => { this.updateButtonsVisibility(); });

this.onGetQuestionNo.onCallbacksChanged = () => {
this.resetVisibleIndexes();
Expand Down Expand Up @@ -1396,6 +1399,7 @@ export class SurveyModel extends SurveyElementCore
* - `"none"` - Hides the navigation buttons. This setting may be useful if you [implement custom external navigation](https://surveyjs.io/form-library/examples/external-form-navigation-system/).
* @see goNextPageAutomatic
* @see showPrevButton
* @see showCompleteButton
*/
public get showNavigationButtons(): string | any {
return this.getPropertyValue("showNavigationButtons");
Expand All @@ -1412,13 +1416,25 @@ export class SurveyModel extends SurveyElementCore
/**
* Specifies whether to display the Previous button. Set this property to `false` if respondents should not move backward along the survey.
* @see showNavigationButtons
* @see showCompleteButton
*/
public get showPrevButton(): boolean {
return this.getPropertyValue("showPrevButton");
}
public set showPrevButton(val: boolean) {
this.setPropertyValue("showPrevButton", val);
}
/**
* Specifies whether to display the Complete button. Set this property to `false` if respondents should not complete the survey.
* @see showNavigationButtons
* @see showPrevButton
*/
public get showCompleteButton(): boolean {
return this.getPropertyValue("showCompleteButton", true);
}
public set showCompleteButton(val: boolean) {
this.setPropertyValue("showCompleteButton", val);
}
/**
* Gets or sets the visibility of the table of contents.
*
Expand Down Expand Up @@ -4251,7 +4267,7 @@ export class SurveyModel extends SurveyElementCore
const state = this.state;
return this.isEditMode && (this.state === "running" &&
(this.isLastPage && !this.isShowPreviewBeforeComplete || this.canBeCompletedByTrigger)
|| state === "preview");
|| state === "preview") && this.showCompleteButton;
}
private calcIsPreviewButtonVisible(): boolean {
return (
Expand Down
37 changes: 37 additions & 0 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,43 @@ QUnit.test("isShowNext/Prev/Complete buttons and showPreviewBeforeComplete: show
survey.mode = "edit";
assert.equal(survey.isCompleteButtonVisible, true, "isCompleteButtonVisible, edit mode #5");
});
QUnit.test("isShowPrevButton/isCompleteButtonVisible & showPrevButton/showCompleteButton", function (
assert
) {
const survey = new SurveyModel({
showPrevButton: false,
pages: [
{
elements: [{ type: "text", name: "q1" }]
},
{
elements: [{ type: "text", name: "q2" }]
}
]
});
survey.showCompleteButton = false;

assert.equal(survey.currentPageNo, 0, "Init current page");
assert.equal(survey.isShowPrevButton, false, "prev #1");
assert.equal(survey.isCompleteButtonVisible, false, "complete #1");
assert.equal(survey.navigationBar.getActionById("sv-nav-prev").isVisible, false, "sv-nav-prev, #1");
assert.equal(survey.navigationBar.getActionById("sv-nav-complete").isVisible, false, "sv-nav-complete, #1");

survey.nextPage();
assert.equal(survey.currentPageNo, 1, "second page");
assert.equal(survey.isShowPrevButton, false, "prev #2");
assert.equal(survey.isCompleteButtonVisible, false, "complete #2");
assert.equal(survey.navigationBar.getActionById("sv-nav-prev").isVisible, false, "sv-nav-prev, #2");
assert.equal(survey.navigationBar.getActionById("sv-nav-complete").isVisible, false, "sv-nav-complete, #2");

survey.showPrevButton = true;
survey.showCompleteButton = true;
assert.equal(survey.currentPageNo, 1, "second page, #2");
assert.equal(survey.isShowPrevButton, true, "prev #3");
assert.equal(survey.isCompleteButtonVisible, true, "complete #3");
assert.equal(survey.navigationBar.getActionById("sv-nav-prev").isVisible, true, "sv-nav-prev, #3");
assert.equal(survey.navigationBar.getActionById("sv-nav-complete").isVisible, true, "sv-nav-complete, #3");
});
QUnit.test("Next, Prev, IsFirst and IsLast Page and progressText", function (
assert
) {
Expand Down

0 comments on commit f37e605

Please sign in to comment.