Implement External Form Navigation
SurveyJS ships with multiple navigation features that you can add to your forms: navigation buttons, a table of contents, and various types of progress indicators. You can also implement custom navigation elements that extend the built-in functionality or completely replace it. This demo shows how to implement external form navigation controls—a page selector, navigation buttons, and a progress indicator—and use them in conjunction with built-in form navigation features.
Configure a Page Selector
A page selector is a UI element that displays a list of survey pages and enables users to jump to a selected page. Usually, a page selector is a drop-down menu. If your survey contains a few pages only, a page selector can be a set of buttons with page numbers.
This example demonstrates a drop-down page selector built upon a standard <select>
HTML element. To fill <select>
options, iterate over SurveyModel
's visiblePages
array and create an <option>
element for each array item. Within the <select>
element's onchange
event handler, call the current page's validate()
method to perform validation. If all answers on the current page are valid, assign the selected page number to SurveyModel
's currentPageNo
property. Note that this property starts to enumerate survey pages with 0.
Implement Navigation Buttons
Built-in survey navigation buttons include Start, Next Page, Previous Page, Preview, and Complete. Depending on your use case, you may need to implement all the buttons or only a part of them. This demo implements the Next Page, Previous Page, and Complete buttons.
Add <button>
elements to your page. To navigate between survey pages, call SurveyModel
's nextPage()
and prevPage()
methods within <button>
's onclick
event handler. To end the survey, call the completeLastPage()
method.
Navigation button visibility may depend on the current page. For example, the Previous Page button should not be visible on the first survey page, or the Complete button should appear only when a user has reached the last page. To control button visibility, use SurveyModel
's isFirstPage
and isLastPage
properties or compare the currentPageNo
property value with the length of the visiblePages
array.
If you implement custom navigation buttons, you may want to hide the built-in buttons to avoid functionality duplication. To do this, disable the showNavigationButtons
property. This demo, however, keeps the built-in buttons visible to show how they can work alongside custom buttons.
Add a Progress Indicator
A progress indicator helps users understand how far along the survey they have advanced. Progress indicators can show the number of completed survey pages, answered questions, or other progress information. In this demo, a progress indicator displays the current page number and the total number of survey pages. Use SurveyModel
's currentPageNo
property and the length of the visiblePages
array to implement this progress indicator. Note that currentPageNo
starts to enumerate survey pages with 0. Therefore, you need to add 1 to its value to get the actual current page number.
Handle Navigation Events
A survey raises the following events that may be useful when you implement an external navigation system:
onStarted
Raised when the survey starts.onCurrentPageChanged
Raised after the current page is switched.onComplete
Raised after the survey is completed.