Search code examples
javascriptsurveyjs

How to modify SurveyJS page property after timeout (minimum time)?


I'm trying to set minimum time for a question in a SurveyJS survey. I want the navigation buttons to appear only after a certain time (3 seconds in the example). Yet when I try to modify navigationButtonsVisibility using JS's setTimeout() it doesn't work.

const showNavigation = function () {
  console.log("show navigation"); // debug
  survey.currentPage.navigationButtonsVisibility = "show";
};

survey.onCurrentPageChanged.add((sender, options) => {
  setTimeout(showNavigation, 3000);
});

The showNavigation() function runs but the buttons do not appear. It works outside setTimeout() so it could be a scoping problem. I use React.


Solution

  • I made it according to this question.

    survey.onCurrentPageChanged.add((sender, options) => {
        let nextButton = survey.navigationBar.getActionById("sv-nav-next");
        nextButton.visible = false;
        setTimeout(function () {
          nextButton.visible = true;
        }, 3000);
    });