goxiaoy / flutter_survey_js

Flutter client library for parsing and display surveyjs.io survey
https://goxiaoy.github.io/flutter_survey_js/
MIT License
16 stars 17 forks source link

`Checkbox`es with `isRequired` property do not validate when passing a `builder` to `SurveyWidget` #85

Closed ChopinDavid closed 1 year ago

ChopinDavid commented 1 year ago

Describe the bug Checkboxes with the isRequired property will display the required validator error when SurveyWidget.builder is non-null. The required validator error does appear when SurveyWidget.builder is null.

To Reproduce

  1. Set complex.json to the following JSON:
    {
    "pages": [
    {
      "elements": [
        {
          "type": "checkbox",
          "name": "question1",
          "title": "Pizza toppings can include...",
          "isRequired": true,
          "choices": [
            {
              "value": "Item 1",
              "text": "Pepperoni"
            },
            {
              "value": "Item 2",
              "text": "Shrimp"
            },
            {
              "value": "Item 3",
              "text": "Chai tea"
            },
            {
              "value": "Item 4",
              "text": "Cheez Its"
            }
          ],
          "showNoneItem": true,
          "showSelectAllItem": true,
          "showOther": true
        }
      ]
    }
    ]
    }
  2. Launch the example
  3. Click "Next" in the top-right corner
  4. Click "Customize"
  5. Click "Submit" without checking any boxes

Expected behavior The "required" validator error should appear under the Checkbox element.

Actual behavior The "required" validator error does not appear under the Checkbox element.

  1. Go back one page
  2. Click "Simple"
  3. Click "Submit" without checking any boxes

Behavior The "required" validator error does appear under the Checkbox element.

Screenshots

https://github.com/goxiaoy/flutter_survey_js/assets/27712906/e16cf57e-5644-4c38-bebd-7fdd04111e8e

Smartphone (please complete the following information): Any

Context Our team is seeing this same issue in our production app that uses a SurveyWidget with a custom, non-null builder: property.

laogao commented 1 year ago

Unfortunately we don't use custom builders in our app so not being able to quickly reproduce the error on my side. Could you provide a minimal working builder that demonstrates this behavior? I'm trying to figure out the difference between using custom builders and the built-in one.

ChopinDavid commented 1 year ago

@laogao If you use the JSON provided above, you are able to reproduce it in the example app. Step 4, i.e. "Click 'Customize'", will launch the app using a builder instead of the default. See this line of code: https://github.com/goxiaoy/flutter_survey_js/blob/d2fb00b539d13f4bd0e0749579adf56027f502bd/example/lib/components/custom_layout.dart#LL34C16-L34C54

CustomLayoutPage, the class containing the code snippet above, is pushed when clicking "Customize" while running the example app.