surveyjs

How to show timer only for pages with time limit in SurveyJS?


When I run a SurveyJS survey with showTimerPanel='top', the timer appears everywhere. Can I make it appear only on certain pages? Or at least the pages with time limit.


Solution

  • You can setup the timer panel and start/stop timer on starting the survey and on current page change. Here is the code and example in plunker.

    function setupTimerPanel(survey) {
        const showTimer = survey.currentPage.maxTimeToFinish;
        survey.showTimerPanel = showTimer ? "top" : "none";
        if(showTimer) {
            survey.startTimer();
        } else {
            survey.stopTimer();
        }
    }
    survey.onCurrentPageChanged.add((sender, options) => {
       setupTimerPanel(survey);
    });
    survey.onStarted.add((sender, options) => {
        setupTimerPanel(survey);
    });
    

    Please note, if you don't have a started page, then you need to call setupTimerPanel(survey); for your first page after creating the Survey model.

    Thank you, Andrew