Question T605
Visible to All Users

Hide/show questions based on external factors.

created 7 years ago

Is there a way to hide and show questions based on factors other than the currently filled in questions and their values?

We are using visibleIf to show/hide questions depending on question answers, but there is one set of questions we want to show depending on whether the user is logged in to our application or not.

Ideally we would do something like "visibleIf": "({hasAccount} = false" BUT hasAccount would not be a questionName, it would be something our application determines and sets itself.

Any help/advice on how to do this appreciated! Thanks in advance

Comments (1)

    Should probably clarify that it is not as simple as loading one set of questions for a logged in user and another for a logged out user, as we potentially log them in halfway through the survey via AJAX, once they have entered their email in the email question.

    Answers

    created 7 years ago

    Hello Sarah,
    I would suggest to use the custom function: https://surveyjs.io/Examples/Library/?id=condition-customfunctions
    so you will havel a function hasAccount and the expression will be: "hasAccount() = false"

    Thank you,
    Andrew
    SurveyJS Team

      Show previous comments (2)

        It will be possible to use surve.setVariable() from the next minor update.
        The issue is fixed with this commit: https://github.com/surveyjs/surveyjs/commit/0467e393ff546f36c70cce05d22cd15a8349fd41, unit test is added.

        Thank you,
        Andrew
        SurveyJS Team

          Hi Andrew,

          That seems to be working better, however I am getting another problem:

          I have a password question which is "visibleIf": "({hasExistingAccount} = true && {isUserLoggedIn} = false)".

          When the user enters their password, I log them in (via AJAX, within onValidateQuestion), set isUserLoggedIn to false as you describe, do survey.nextPage(), but then for some reason I am taken back to the beginning of the survey. Is this because the current question/page I am on is hidden by setting the value?

          In my survey, there is only one question per page.

          Thanks for your help

          Sarah

            Think I have answered my own question, I have changed it to run survey.nextPage() before setting the values and now it is working as expected.