Question T3383
Visible to All Users

Trigger function only when clicking next button

created 5 years ago

Hello,

I am trying to fill a portion of a progression bar when clicking only the next button, but I only found the events onCurrentPageChanging and onCurrentPageChanged to do so: when I use them, clicking on the previous button also fills the progression bar, which I don't need.

I saw on your API that option.oldCurrentPage might help me, but I don't understand how I can use it. Could you help me with this please ? I work with ReactJS.

Thanks in advance,

Mehdi M.

Show previous comments (5)

    Alright! Thank you :)

    One more thing if I may, and if that's not too much trouble: I'm not sure on how to add an option to an existing event of your API. Is this implementation okay?

    survey.onCurrentPageChanged.add(function(options) {
    if (!!option.oldCurrentPage && !!option.newCurrentPage && option.newCurrentPage.visibleIndex === option.oldCurrentPage.visibleIndex + 1 ) {
    // handle the progress bar when the user clicks on prev page
    }
    })

    Because I tried something similar a few days ago, but the behaviour of onCurrentPageChanged didn't seem to change.

      Sure, here is the correct code.

      JavaScript
      survey.onCurrentPageChanged.add(function(sender, options) { if (!!option.oldCurrentPage && !!option.newCurrentPage && option.newCurrentPage.visibleIndex \=\=\= option.oldCurrentPage.visibleIndex + 1 ) { // handle the progress bar when the user clicks on prev page } });

      Thank you,
      Andrew
      SurveyJS Team

        Great. Many thanks!

        Mehdi M.