Question T4189
Visible to All Users

Add click event listener onAfterRenderPage

created 5 years ago

Hi,

I would need to auto navigate page to the next page on radio button selection, that we can handle in onValueChanged event. If user will go back with Previous link and click on the same previously selected answer, it should trigger the click event and go to the next page, which will not work in onValueChanged event.

I tried to add click event listener onAfterRenderPage, but it is not triggered on every page change.

Here, next button is disable for radiogroup question.

Answers approved by surveyjs Support

created 5 years ago
    created 5 years ago

    Hello,

    You can use the https://www.surveyjs.io/Documentation/Library?id=surveymodel#onCurrentPageChanged event

    Thanks, Serge
    SurveyJS Team

      Other Answers

      created 5 years ago

      Hello,

      You can use the https://surveyjs.io/Documentation/Library?id=surveymodel#onAfterRenderQuestionInput event.

      Here is the live plunker sample - https://plnkr.co/edit/He8GMeYjuSxdUZHL

      Hope it fit your needs.

      Thanks, Serge
      SurveyJS Team

        Comments (2)

          Hello,
          Are you sure that you can't use auto next page functionality. Here is the example.

          Thank you,
          Andrew
          SurveyJS Team

            Thanks Serge.

            Example given by you was helpful. It is working fine now.

            created 5 years ago

            onCurrentPageChanged event will be called after page will changed, here, I would need to navigate page on click of Radio button. So, it should not come under onCurrentPageChanged

              Comments (3)

                Hi,

                I did it using onCurrentPageChanged event and it is working fine. Still I have one question.

                First of all I fetch all radio buttons using below code and added click event listener on that.

                If user will click Previous link and click on previously selected answer, we are getting previous page radio group HTML collection, if we do not use setTimeOut.

                JavaScript
                document.getElementsByClassName( 'sv_q_radiogroup_control_item')

                Please do needful.

                  Hello,

                  If you want to access the question markup you need to use the https://surveyjs.io/Documentation/Library?id=surveymodel#onAfterRenderQuestion event as I suggested you in my previous answer.

                  Thanks, Serge
                  SurveyJS Team

                    I tried with onAfterRenderQuestion, onAfterRenderQuestionInput, but on first page load, it is not navigate to the next page after selecting radio button.

                    JavaScript
                    const radioButton = document.getElementsByClassName( 'sv_q_radiogroup_control_item', ) for (let x = 0; x < radioButton.length; x++) { const radioElement = radioButton[x] radioElement.onclick = () => { model.nextPage() } }

                    Even, if we refresh page and then trying to select the radio button, it is not navigating to the next page.