2

I am using SurveyJS (https://surveyjs.io/) to make a simple site with few questions. I am able to do all my logic with the options provided by SurveyJS.

However, what I'm looking to do is:

  • Make an API call after one of the question (working as expected)
  • Wait for the API call before moving to the next question (working as expected)
  • If the API responds false, do NOT move to the next question. (not working)

No matter what I do, the survey continues to move to next question and I want to avoid that in this case.

Three callbacks that are available:

// triggers before the current page goes away
survey.onCurrentPageChanging.add(function (sender, options) {
    if(survey.data.year === "1991") {
        // let's say I want to stop user from going forward at this point.
        // how can I do that?
    }
});


// triggers after the current page is gone and new page is about to appear
survey.onCurrentPageChanged.add(function (sender) {

});


// triggers right before the survey is about to finish - the last page
survey.onCompleting.add(function (sender, options) {

});

Thank you for your time.

ᴛʜᴇᴘᴀᴛᴇʟ
  • 4,466
  • 5
  • 39
  • 73

1 Answers1

1
survey.onCurrentPageChanging.add(function (sender, options) {
    if(survey.data.year === "1991") {
        // This prevents survey go to the next page
        options.allowChanging = false;
    }
});
TSV
  • 7,538
  • 1
  • 29
  • 37