surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.18k stars 808 forks source link

Conditionally-rendered questions are not showing in React #1861

Closed Chris-Boe closed 4 years ago

Chris-Boe commented 5 years ago

Are you requesting a feature, reporting a bug or asking a question?

Reporting a bug

What is the current behavior?

With a survey of 3 or more pages, conditionally-rendered questions do not show up when the condition is met. If the hidden question(s) are required, you cannot move forward to the next page.

What is the expected behavior?

Conditionally-rendered questions should show up

How would you reproduce the current behavior (if this is a bug)?

Created a new project with https://github.com/surveyjs/surveyjs_react_quickstart and replaced the JSON with the attached json. When we upgraded to 1.1.14 of survey-react in our main react project, this bug appeared (no other code changes happened). I tested this survey before and after 1.1.14. It is only broken from 1.1.14 and up

Provide the test code and the tested page URL (if applicable)

Tested page URL: https://plnkr.co/edit/Y2ZCvBLaAGFcD4aLTLAP?p=preview

Test code

The only thing I changed after cloning https://github.com/surveyjs/surveyjs_react_quickstart was the JSON being used for the survey:

{ "title": "Global Tokenized Simple", "completedHtml": "<h3>Thank you for completing the questionnaire!</h3>", "pages": [ { "name": "intro", "elements": [ { "type": "html", "name": "intro_page-intro", "html": "{{intro_intro}}" }, { "type": "checkbox", "name": "attest", "title": "Please check the box before continuing.", "isRequired": true, "requiredErrorText": "You must agree to the acknowledgement above before continuing.", "titleLocation": "hidden", "choices": [ { "value": "true", "text": "I attest that the information I provide in this Questionnaire is true and accurate to the best of my knowledge and belief." } ] } ], "title": "Introduction" }, { "name": "oi_page", "elements": [ { "type": "html", "name": "oi_page-intro", "html": "{{oi_intro}}" }, { "type": "radiogroup", "name": "oi_primary", "riskCategoryCode": "OI", "title": "Page 1: Answering YES should display a follow-up question.", "description": "Select one", "isRequired": true, "choices": [ "Yes", "No" ] }, { "type": "comment", "name": "oi_details", "visible": false, "visibleIf": "{oi_primary} = \"Yes\"", "title": "Please provide an explanation:", "isRequired": true } ], "title": "Personal Financial Interests" }, { "name": "bp_page", "elements": [ { "type": "html", "name": "bp_page-intro", "html": "{{bp_intro}}" }, { "type": "radiogroup", "name": "bp_primary", "riskCategoryCode": "BP", "title": "Page 2: Answering YES should display a follow-up question.", "description": "Select one", "isRequired": true, "choices": [ "Yes", "No" ] }, { "type": "comment", "name": "bp_details", "visible": false, "visibleIf": "{bp_primary}==\"Yes\"", "title": "Please provide an explanation:", "isRequired": true } ], "title": "For-Profit Board Participation" }, { "name": "ge_page", "elements": [ { "type": "html", "name": "ge_page-intro", "html": "{{ge_intro}}" }, { "type": "radiogroup", "name": "ge_primary", "riskCategoryCode": "GE", "title": "Page 3: Answering YES should display a follow-up question.", "description": "Select one", "isRequired": true, "choices": [ "Yes", "No" ] }, { "type": "comment", "name": "ge_details", "visible": false, "visibleIf": "{ge_primary} = \"Yes\"", "title": "Please provide an explanation:", "isRequired": true } ], "title": "Accepting Gifts" }, { "name": "oe_page", "elements": [ { "type": "html", "name": "oe_page-intro", "html": "{{oe_intro}}" }, { "type": "radiogroup", "name": "oe_primary", "riskCategoryCode": "OE", "title": "Page 4: Answering YES should display a follow-up question.", "description": "Select one", "isRequired": true, "choices": [ "Yes", "No" ] }, { "type": "comment", "name": "oe_details", "visible": false, "visibleIf": "{oe_primary} = \"Yes\"", "title": "Please provide an explanation:", "isRequired": true } ], "title": "Outside Employment" } ], "sendResultOnPageNext": true, "showQuestionNumbers": "off", "questionErrorLocation": "bottom", "showProgressBar": "top", "startSurveyText": "Start", "pagePrevText": "Previous", "pageNextText": "Next" }

Specify your

Chris-Boe commented 5 years ago

I was able to reproduce this bug in the pre-built Plunker (found by hitting "Edit in Plunker" here ) using the JSON above: https://plnkr.co/edit/Y2ZCvBLaAGFcD4aLTLAP?p=preview

andrewtelnov commented 5 years ago

@Chris-Boe I have fixed the issue. The bug was introduced after rewritting code because several methods became depricated in react: componentWillUpdate() and componentWillRecieveProps. As result we had to rewrite our code to make sure it works for the latest versions. Unfortunately, we did not use componentDidUpdate method to take into account that component props could be changed. The commit above fix this issue and make the code more clear. We will include fix into the next minor release, that we will release on next week.

Thank you, Andrew