Giter VIP home page Giter VIP logo

flutter_survey_js's People

Contributors

chopindavid avatar goxiaoy avatar jonestyler avatar laogao avatar vpdwivedi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flutter_survey_js's Issues

Date values should be `jsonEncode`-able

Describe the bug
When submitting a survey with dates, the answer is currently not jsonEncode-able. Instead, the following error will be thrown:

errors.dart:288 Uncaught (in promise) Error: Converting object to an encodable object failed: Instance of 'DateTime'

To Reproduce
SurveyJs json

{
    "title": "datetime jsonEncode issue",
    "logoPosition": "right",
    "pages": [
        {
            "name": "page1",
            "elements": [
                {
                    "type": "text",
                    "name": "102 visit date",
                    "title": "Visit Date",
                    "isRequired": true,
                    "inputType": "date"
                }
            ]
        }
    ],
    "showQuestionNumbers": "off"
}

SurveyJs answer

{"102 visit date": 2023-06-07 00:00:00.000}

Expected behavior
The answer is properly encoded in JSON:

  onSubmit: (v) async {
    print(jsonEncode(v));
  },

Here's how surveyjs.io handles the same input:

{"102 visit date": "2023-06-07"}

Screenshots

Desktop (please complete the following information):

  • OS: macOS/Web
  • Browser: Chrome

Make `SurveyController` attach to `SurveyProvider`

Currently, SurveyController is not being attached to SurveyProvider. The user can pass SurveyController into SurveyWidget, but this controller is never actually used. Attaching SurveyController to SurveyProvider will allow developers to reference the current SurveyController off of context and use SurveyController functionality within the SurveyWidget's builder.

Feature: checkbox to support `showSelectAllItem`, `showNoneItem`, `showOtherItem`, `noneText`, `otherText`.

hasSelectAll basically means when checked/unchecked, all "regular" checkboxes are all checked/unchecked.
hasNone is meant to add a choice of "none of the above", and when checked, all other selections are cleared.
hasOther is meant to add a choice of "other", and when checked, an additional text field shows up.

e.g.

{
  "type": "checkbox",
  "name": "Q099",
   "title": "Q099",
  "choices": [
    "item1",
    "item2",
    "item3"
  ],
  "hasSelectAll": true,
  "hasNone": true,
  "noneText": "None",
  "hasOther": true,
  "otherText": "Other:"
 },

Text Elements that do not have an `inputType` do not create validators when their `isRequired` is true

Consider the following JSON:

{
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "text",
          "name": "email",
          "title": "Your e-mail:",
          "isRequired": true,
          "inputType": "email"
        },
      ]
    }
  ]
}

building a form with this JSON will put a validator on the field so that attempting to submit this field as empty will show an error:
Screen Shot 2023-03-09 at 2 29 03 PM

If we remove "inputType":"email" from the above JSON:

{
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "text",
          "name": "email",
          "title": "Your e-mail:",
          "isRequired": true
        },
      ]
    }
  ]
}

attempting to submit with this field empty will not show an error:

issue.mov

Per Survey.js documentation, this is inconsistent with how officially support Survey.js frameworks handle isRequired:

The Required validator ensures that a question value is not empty. Enable a question's isRequired property to add the Required validator to this question.

Makes the question required. If a respondent skips a required question, the survey displays a validation error.

Feature: provide means to react on form validation errors

Currently, when sumbit() is triggered, either the form is valid (in which case user provided onSubimt is called), or the entire form is touched (in which case the validation errors, if any, are shown on the form itself, and that's it).

For the second case, especially in a multipage setting, the end-user is left in a state where the problem might not be obvious.

Thus it would be useful to provide a means to specify what to do with validation errors, e.g., from as simple as a toast of sorts, to more advanced usages such as extra logic in custom controllers.

Support for expression

The surveyjs javascript use pegjs to parse expression, and use condition runner to provide logic features

  • triggers
    • runexpression
  • calculatedValues
  • question logic
    • visibleIf
    • enableIf
    • defaultValueExpression
    • choicesVisibleIf
    • choicesEnableIf
  • question type
    • expression

original codes :
https://github.com/surveyjs/survey-library/tree/master/src/expressions
https://github.com/surveyjs/survey-library/blob/master/src/conditions.ts
https://github.com/surveyjs/survey-library/blob/master/src/conditionsParser.ts
https://github.com/surveyjs/survey-library/blob/master/src/conditionProcessValue.ts

Paths to achieve this

Index Path Desc Implement difficulty Maintain difficulty
1 Fully rewrite with dart 💪 ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
2 Use js engine in dart Build tools to convert original js codes to single file. and run as js in dart ⭐⭐⭐⭐ ⭐⭐
3 Rewrite with antlr4 rewrite expression parser with antlr4, ⭐⭐⭐⭐ ⭐⭐⭐
4 Use WebAssembly (WASM) compile js into WASM and embed it into Flutter Unknown Unknown

Discussion: scaffold for validation messages at question level

status quo

  • reactive_forms is heavily used
  • reactive_forms does not have a concept for questions (which survey.js uses at its core to model survey questions)
  • reactive_forms's validators are wired at widget level
  • reactive_forms's main user base seems to be those who build online forms according to requirements and usually from scratch, we, however, are expected to take whatever the survey.js creator throws at us
  • flutter_survey_js's most obvious use case for validators is the isRequired attribute specified at question level
  • flutter_survey_js's question usually consists of multiple widgets (either reactive or not)
  • flutter_survey_js's question sometimes map to more than one form control values (see #52 (comment) and #81)
  • the "validation" can happen at form level (when forms are submitted)
  • or widgets level (when individual reactive widgets are touched)
  • validation errors are for the widget (or the caller) itself to parse and decide what to do (e.g. render an error message in red)

a similar concept

We already have a mechanism (or "wrap") for question titles. In the same vein, maybe we can come up with something similar? E.g. at the bottom of each question, we can choose to display an error message.

additional goodies

Once we have this "question-level validation message" in place, l10n of the required message would be a breeze: currently if one is to provide a l10n message for required, he/she'll have to patch (at each reactive form widget's constructor) something like validationMessages: {'required': (error) => '必填'}.

update 20230528: as pointed out by @goxiaoy the l10n of required validation messages can be handled at global/application level via a ReactiveFormConfig.

Survey response data for elements that support the `showOtherItem` property do not match the web

Describe the bug
Survey response data for elements that support the showOtherItem property do not match the web.

To Reproduce
Create a survey with an element that supports showOtherItem (such as Dropdown, Checkbox, and soon Radiogroup upon completion of #71). Select the "Other" option and enter a response into the text field. Submit your survey.

SurveyJs json

{
 "pages": [
  {
   "name": "page1",
   "elements": [
    {
     "type": "checkbox",
     "name": "question1",
     "choices": [
      "Item 1",
      "Item 2",
      "Item 3"
     ],
     "showOtherItem": true
    }
   ]
  }
 ]
}

Expected behavior
Expected SurveyJs answer

{
  "question1": [
    "other"
  ],
  "question1-Comment": "Some other response"
}

Actual behavior
Actual SurveyJs answer

{
  "question1": [
    "Some other response"
  ]
}

Screenshots

Web:

Untitled.video.mp4

Mobile:

Screen.Recording.2023-05-26.at.9.26.37.AM.mov

Smartphone (please complete the following information):

  • Any

Additional context
I was able to make the output for the Checkbox correct in this commit by adding a _commentsStatusMap alongside the already-existing _statusMap in the ElementState class. I also modified the elementsToFormGroup method to take a commentsControlsMap along side the already-existing controlsMap . The same goes for the toFormObjects method. Finally, I added a means to register/map survey element types to their respective comment controls in SurveyElementFactory. This commit is difficult to pull in in its current state as there is a bit of now-irrelevant Checkbox changes in this commit as well. But let me know what you all think of this approach for essentially registering a new FormControl for all of the elements that supports showOtherItem.

Bug: `Dropdown`s without a specified `placeholder` should default to `"Submit..."` or `"请选择..."`

Whenever you paste

{
 "title": "Single Page Survey",
 "pages": [
  {
   "name": "page1",
   "elements": [
    {
     "type": "dropdown",
     "name": "question1",
     "choices": [
      "Item 1",
      "Item 2",
      "Item 3"
     ]
    }
   ]
  }
 ]
}

into https://surveyjs.io/create-free-survey and switch to the "Preview" tab, you will notice that the Dropdown displays Select... or 请选择... despite "placeholder": "Select..." not existing in the input JSON. This is how the web frameworks render this JSON as well.

Web:

Screen Shot 2023-04-13 at 1 24 33 PM

Screen Shot 2023-04-13 at 1 52 01 PM

Our framework:

Screen Shot 2023-04-13 at 1 28 19 PM

Whenever "placeholder" does not exist in the Dropdown JSON, we should default to showing Select... or 请选择... for English or Chinese, respectively.

Framework does not fail gracefully when attempting to parse unsupported element types

There are some SurveyJS elements that are not supported by flutter_survey_js, such as tagbox.

The following JSON will throw Unhandled Exception: Unsupported operation: ElementBase at package:flutter_survey_js/model/element.dart:41 and perpetually show a CircularProgressIndicator:

{
  "title": "Software developer survey.",
  "pages": [
    {
      "elements": [
        {
          "type": "tagbox",
          "choicesByUrl": {
            "url": "https://surveyjs.io/api/CountriesExample"
          },
          "name": "countries",
          "title": "Which countries have you visited within the last three years?",
          "description": "Please select all that apply."
        }
      ]
    }
  ]
}

This is because "tagbox" is not a type that maps to any class subclassing ElementBase.

RadioGroupElements with `isRequired` true are not getting `isRequired` validators

Consider the following survey.js JSON:

{
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "radiogroup",
          "name": "question1",
          "title": "What is your T-Shirt size?",
          "isRequired": true,
          "choices": [
            {
              "value": "small",
              "text": "S"
            },
            {
              "value": "medium",
              "text": "M"
            },
            {
              "value": "large",
              "text": "L"
            }
          ]
        }
      ]
    }
  ]
}

A Survey.js element created from this JSON will show a required radio group. Attempting to submit a survey with this radio group in an unselected state should show an error.

In reality, attempting to submit a survey with this radio group in an unselected state successfully submits:

issue6.mov

This issue is pretty similar to Issue #5, but the cause is likely quite different.

Feature: add ability to hide survey title

If somebody wants to display the survey's title in the Scaffold's AppBar rather than at the top of the survey, there is currently no way to do this.

We are thinking of, similarly to what was suggested in Issue #14, creating a SurveyStylesConfiguration that is a part of the SurveyProvider that has a shouldShowTitle boolean. Then, if somebody wanted to hide the title of the survey within the SurveyWidget (in order to display it elsewhere, like in the AppBar), it could look something like this:

class SurveyStylesConfiguration {
  SurveyStylesConfiguration({this.shouldShowTitle = true});
  bool shouldShowTitle;
}

class SomeWidget extends StatelessWidget {
  SomeWidget({required Survey this.survey});
  final Survey survey;

  @override
  Widget build(BuildContext context) {
    return  Scaffold(
      appBar: AppBar(
        title: Text(survey.title,),
      ),
      body: SurveyWidget(
        survey: survey,
        stylesConfiguration:
          SurveyStylesConfiguration(
            shouldShowTitle: false, 
          ),
    );
  }
}

Make it so that we are only utilizing a `PageView` when a `Survey` contains more than one page

Right now, SurveyWidget is utilizing a PageView via PageView.builder regardless of if the user is trying to view a one-page or a multiple-page Survey. There are benefits to not having a PageView in your widget hierarchy. Namely, it is very difficult to wrap a PageView within a ScrollView. Using a PageView only when we need to will enable users to use custom scroll views when viewing a one-page survey.

Our team needs this in conjunction with Issue #19 to make our designs work. If you feel this doesn't benefit the framework, my team can just keep it on our fork.

Bug: checkbox should be able to deduce "other" from answer

Current implementation ignores possible other value stored in or passed over via answer. It starts with a state of "other" that is always unchecked. I'd like to improve on this by having checkboxes deduce the state and value of "other" from answer. Something along the lines of the following:

  1. If the answer array contains anything that's not in choices, and showOtherItem is set to true, then the "other" item is checked and the text field associated with it is filled with that (supposedly single) value;
  2. If the answer array only contains values present in choices, and showOtherItem is set to true, then the "other" item in unchecked.

Once it's done and tested, I'll submit a PR. Suggestions are welcome.

Required `Checkbox` elements are automatically displaying an error without being touched and without the survey being validated.

Describe the bug
Checkbox elements with isRequired: true are displaying the isRequired error immediately upon displaying the survey. To match the web, we should not display the isRequired error until the element is either touched, or the survey is validated with none of the choices checked.

To Reproduce
SurveyJs json

{
  "questions": [
    {
      "type": "checkbox",
      "name": "question1",
      "isRequired": true,
      "choices": [
        "Item 1",
        "Item 2"
      ]
    }
  ]
}

Expected behavior
The "question1" element should not display the isRequired error message until either the Checkbox element is touched or the survey is validated.

Screenshots

Screen.Recording.2023-05-24.at.11.12.26.AM.mov

Desktop (please complete the following information):
N/a

Smartphone (please complete the following information):
Any

Feature: add parameter to make `SurveyWidget` non-scrollable

Right now, the scroll behavior of SurveyWidget is not very flexible. If a developer wants to make it so that their submit button is only visible when the user has scrolled to the bottom of the page, there is currently no way to accomplish this. The submit button, in its current state, is always visible on the screen:

Screen.Recording.2023-03-17.at.12.37.49.PM.mov

Making the SurveyWidget non-scrollable allows us to wrap it with our own scroll view, so that we can make something like this:

betterScrolling.mov

Feature: add `defaultValue` support for all elements

Right now, only a handful of elements actually reflect their defaultValue. We should make as many elements as we can reflect their defaultValue.

The following elements have defaultValue support (pending the merging of #72 and #73):

  • matrixdropdown
  • matrixdynamic
  • matrix
  • expression
  • checkbox
  • ranking
  • radiogroup
  • imagepicker
  • dropdown
  • text
  • multipletext
  • html
  • image
  • comment
  • file
  • rating
  • boolean
  • signaturepad
  • paneldynamic
  • panel

`Rating` elements hide number when selected

When selecting a value from a Rating element, the fill-color and the text-color are the same. We would like to make the text-color of the selected value white so that it is still readable.
Screen Shot 2023-03-20 at 9 18 38 AM

Bug: `Survey.showQuestionNumbers` is not respected when value is `onPage`

Per SurveyJS documentation, Survey has a showQuestionNumbers property. When showQuestionNumbers is set to onPage, the documentation explains that the survey should "display question numbers, start numbering on every page".

With the current implementation of flutter_survey_js, question numbering is disabled when we construct a Survey with JSON containing "showQuestionNumbers": "onPage".

Steps to reproduce the issue:

  1. Open /example/assets/multi_page.json
  2. Change "showQuestionNumbers": false, to "showQuestionNumbers": "onPage",
  3. Launch the example app
  4. Choose "Survey with Multiple Pages" from the dropdown on the first page
  5. Click "Next Step" in the top-right corner
  6. Click the "Simple" button

Expected behavior:

All questions are numbered, with the numbering resetting back to 1. when navigating to the second page.

Actual behavior:

No questions are numbered.

Attachments:

Screen.Recording.2023-05-15.at.3.00.30.PM.mov

Developer notes

This issue is caused by survey_widget.dart lines 81-90:

Map<s.Elementbase, ElementStatus> status = {};
  int index = 0;
  for (final kv in _controlsMap.entries) {
    var visible = true;
    status[kv.key] = ElementStatus(indexAll: index);
    if (visible) {
      index++;
    }
  }
final elementsState = ElementsState(status);

we should be setting status[kv.key] on line 85 to an ElementStatus with a defined pageIndex. This is important when we consider question_title.dart lines 40-46:

} else if ((survey.survey.showQuestionNumbers?.isOnPage ?? false) &&
              status.indexInPage != null) {
  return Text(
    '${status.indexInPage! + 1}.',
    style: titleTextStyle(),
  );
}

where we see that Survey.showQuestionNumbers?.isOnPage is only influencing the UI while status.indexInPage is also non-null.

Add labelTrue and labelFalse text to Boolean element

Description

  • The labelTrue and labelFalse text is missing from the Boolean Element
{
 "title": "Single Page Survey",
 "pages": [
  {
   "name": "page1",
   "elements": [
    {
     "type": "boolean",
     "name": "question1",
     "labelTrue": "No Pineapples",
     "labelFalse": "Pineapples"
    }
   ]
  }
 ]
}

Here is how this would render on web
Screen Shot 2023-04-13 at 11 56 03 AM

Here is how it renders in the mobile app:
simulator_screenshot_73562EA9-E84F-4FB7-9505-95D36B6F73A6

`Survey` data model's `showQuestionNumbers` property is not respected

Every Survey numbers its elements, regardless of whether Survey.showQuestionNumbers is on, onPage, or off. This is because we are never using Survey.showQuestionNumbers as a condition for adding Text('${status.indexAll! + 1}.'), as seen on question_title.dart line 45:

final title = () {
  List<Widget> listTitle = <Widget>[];
  listTitle.add(Builder(builder: (context) {
    final survey = SurveyProvider.of(context);
    final status = survey.elementsState.get(q);
    if (status != null && status.indexAll != null) {
      return Text(
        '${status.indexAll! + 1}.',
        style: titleTextStyle(),
       );
    }
    return Container();
  }));

  ...    

};

Feature: add a way to customize basic styling

Right now, the Text widgets that display each survey element have hard-coded styling. For example, the QuestionTitle widget uses the following lines of code to style its Text:

final titleTextStyle = () {
  return TextStyle(
    fontSize: 16.0,
    fontFamily: 'SF-UI-Text',
    fontWeight: FontWeight.w900,
    color: Theme.of(context).disabledColor //Color(0xff242833)
  );
};

...

//later in the code:
Text(
  '${status.indexAll! + 1}.',
  style: titleTextStyle(),
)

I am envisioning a class where we could define the styles for basic UI elements, such as question titles. Implementation would look something like this:

class SurveyStylesConfiguration {
  SurveyStylesConfiguration({this.questionTitleTextStyle});
  TextStyle? questionTitleTextStyle;
}

class SomeWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return  SurveyWidget(
      survey: survey!,
      stylesConfiguration:
        SurveyStylesConfiguration(
          questionTitleTextStyle: TextStyle(
            fontSize: 24.0,
            fontFamily: 'Helvetica',
            fontWeight: FontWeight.w700,
            color: Colors.grey,
          ),
    );
}

Alternatively, instead of passing SurveyStylesConfiguration directly to the SurveyWidget, we could use a provider/singleton pattern to distribute this configuration down a widget tree/across the whole app, respectively.

With reference #79 issue, I am getting type error

Describe the bug
Getting the error '_Map<dynamic, dynamic>' is not a subtype of type 'Map<String, Object?>?' however I am storing the survey response data to HiveBox and then sending the same response data to answer. If I add a survey and edit the same response works fine but Error coms when I restart the application and then going to the edit survey screen.

To Reproduce
SurveyJs json

{
 "title": "Survey Form for Commune",
 "description": "Survey for commune level users",
 "logoFit": "cover",
 "logoPosition": "right",
 "pages": [
  {
   "name": "Page1",
   "elements": [
    {
     "type": "matrixdynamic",
     "name": "question1",
     "title": "Question 1",
     "columns": [
      {
       "name": "Column 1"
      },
      {
       "name": "Column 2"
      },
      {
       "name": "Column 3"
      }
     ],
     "choices": [
      1,
      2,
      3,
      4,
      5
     ]
    }
   ],
   "title": "I. COUVERTURE DES RISQUES SOCIAUX",
   "description": "Tableau001 : Couverture dela population par les mutuelles sociales toutes prestations (Une liste demutuelle sera fournie)"
  },
  {
   "name": "page2",
   "elements": [
    {
     "type": "matrixdynamic",
     "name": "question2",
     "title": "Question1",
     "columns": [
      {
       "name": "Column 1"
      },
      {
       "name": "Column 2"
      },
      {
       "name": "Column 3"
      }
     ],
     "choices": [
      1,
      2,
      3,
      4,
      5
     ]
    }
   ],
   "title": "1.2. Assurance Maladie Obligatoire (AMO)",
   "description": "Tableau 002 : Couverture de la population par l’AMO (interopérabilité entre le SISo et la base de la CANAM)"
  }
 ]
}

SurveyJs answer

{question1: [{Column 1: 2, Column 2: 2, Column 3: 2}], question2: []}

Expected behavior

Screenshots

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]

Additional context

Attempting to parse a Survey with a boolean value for showQuestionNumbers breaks the app

Per SurveyJS documentation, the showQuestionNumbers property for the Survey data model can be either a string or a boolean.

The following JSON will throw Unhandled Exception: type 'bool' is not a subtype of type 'String?' in type cast at package:flutter_survey_js/model/survey.g.dart:55 and perpetually show a CircularProgressIndicator:

{
  "title": "Software developer survey.",
  "pages": [
    {
      "elements": [
        {
          "type": "text",
          "isRequired": true,
          "name": "question 1"
        }
      ]
    }
  ],
  "showQuestionNumbers": true
}

This is because the JSON serializer for the Survey object does not handle booleans, but only strings.

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

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
        }
      ]
    }
  ]
}
  1. Launch the example
  2. Click "Next" in the top-right corner
  3. Click "Customize"
  4. 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

Screen.Recording.2023-05-26.at.1.24.41.PM.mov

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.

Bug: `SurveyWidget.formGroup` is being reset whenever `didUpdateWidget` is called

Description

Whenever didUpdateWidget is called, whenever the keyboard appears on screen or the device orientation changes for example, we invoke rebuildForm if oldWidget.survey != widget.survey. Since this condition is only checking referential equality between the two Surveys, this condition will never be false (as far as I am aware). rebuildForm reassigns the value of formGroup, which sets the values of all of its child FormControls to null.

Expected Behavior

Whenever didUpdateWidget is called, SurveyWidget's formGroup's controls maintain their values.

Current Behavior

Whenever didUpdateWidget is called, SurveyWidget's formGroup's controls are having their values set to null.

Steps to Reproduce

  1. Update the contents of single_page.json to:
{
  "showQuestionNumbers": false,
  "pages": [
    {
      "name": "page1",
      "title": "Single Page Survey",
      "elements": [
        {
          "type": "text",
          "name": "text_question"
        }
      ]
    }
  ]
}
  1. Launch the app
  2. Click "Next Step" in the top-right corner
  3. Click "Simple"
  4. Ensuring "Connect Hardware Keyboard" is turned off on your iOS simulator, type some text into the "text_question" ReactiveTextField
  5. Dismiss the keyboard
  6. Click "Submit"
    You will find that the response json is {text_quesiton: null}.

Note that the response json will not be {text_quesiton: null} if you have "Connect Hardware Keyboard" turned on. This is because the viewport is not adjusting and didUpdateWidget is not being called, which means rebuildForm is not being called.

Attachments:

When keyboard adjusts the viewport:

issue54.mov

When keyboard does not adjust the viewport:

issue54_2.mov

Bug: `showQuestionNumbers` should default to `true`

The Survey object has a showQuestionNumbers property that determines whether question titles are prefixed by their appropriate question number.

This property can be one of 3 values:

  • on - display question numbers
  • onpage - display question numbers, start numbering on every page
  • off - turn off the numbering for questions titles

When pasting the following JSON into SurveyJS's online survey builder, we see that it defaults to the on value.

{
 "title": "Survey",
 "pages": [
  {
   "name": "page1",
   "elements": [
    {
     "type": "dropdown",
     "name": "question1",
     "choices": [
      "Item 1",
      "Item 2",
      "Item 3"
     ],
     "showOtherItem": true,
     "showNoneItem": true
    }
   ]
  },
  {
   "name": "page2",
   "elements": [
    {
     "type": "text",
     "name": "question2"
    }
   ]
  }
 ]
}
Screen.Recording.2023-05-11.at.4.09.40.PM.mov

flutter_survey_js currently does not set a default value for Survey.showQuestionNumbers, which means this value will be null unless otherwise specified, in which case question titles are not prefixed by their appropriate question number. This does not match web behavior, which seems to be defaulting this property to on.

Feature: Add a means to convert single `Page` to a `Survey`

Right now, the SurveyWidget takes a Survey object for its survey property. The JSON for this object might look something like this:

{
  "pages": [
    {
      "name": "page1",
      "title": "Single Page Survey",
      "elements": [
        {
          "type": "text",
          "name": "text_question"
        }
      ]
    }
  ]
}

Our team is finding that, when multi-page/pagination is disabled in our survey builder, we are getting back a Page object back from the API. The JSON for this object might look something like this:

{
    "title": "Single Page Survey",
    "elements": [
        {
          "type": "text",
          "name": "text_question"
        }
    ]
  }

For this reason, we wanted to create a factory constructor on the Survey object that would build a Survey from a single given Page. The alternative to this would be to add a factory constructor on SurveyWidget that takes a single given Page. Any properties that are shared between Page and Survey would be mapped over in a way that makes sense; for example Page's elements property would map to Survey's questions property. description, maxTimeToFinish, questionsOrder, and title are also properties shared between the two objects, amongst others that are not yet being mapped on the frontend (such as timeSpent).

Upgrade reactive_forms to ^15.0.0

ReactiveForms was recently updated to allow FormControl<dynamic> to be passed as a control to fb.group. This would allow us to register dynamic FormControls in lib/ui/survey_element_factory.dart, which we should be able to do given that many elements can represent either a String or a num.

Upgrading this dependency would allow me to resolve #71 because I have written some tests that ensure RadioGroup can handle being provided either an int or a String.

Feature: support `visibleIf` conditions

Right now, the framework does not support visibleIf conditions.

I have implemented basic visibleIf functionality on this branch. There are many things that are not yet supported thus far, such as built in functions as well as condition chaining via and and or. The code can also be cleaned up quite a bit. Just creating this issue so that I don't forget about all of this.

Breaking change: choice values in generated models have different runtime types

Before the openapi codegen overhaul (see a129ec8) , the choice values converted from survey definition had the runtime type of String. Now, after the codegen changes, the runtime type of choice values became StringJsonObject. The runtime type gets reflected in answers as well (if one uses directly the value associated with the choice, that is).

Everything seems to work normally until you jsonEncode the answer where your checkbox value is non-empty . This call would fail with the following error:

Uncaught (in promise) Error: Converting object to an encodable object failed: Instance of 'StringJsonObject'
    at Object.throw_ [as throw] (errors.dart:266:49)
    at convert._JsonStringStringifier.new.writeObject (json.dart:793:7)
    at convert._JsonStringStringifier.new.writeList (json.dart:841:7)
    at convert._JsonStringStringifier.new.writeJsonValue (json.dart:823:7)
    at convert._JsonStringStringifier.new.writeObject (json.dart:784:9)
    at convert._JsonStringStringifier.new.writeMap (json.dart:874:7)
    at convert._JsonStringStringifier.new.writeJsonValue (json.dart:829:21)
    at convert._JsonStringStringifier.new.writeObject (json.dart:784:9)
    at _JsonStringStringifier.printOn (json.dart:982:16)
    at _JsonStringStringifier.stringify (json.dart:967:5)
    at JsonEncoder.convert (json.dart:345:30)
    at JsonCodec.encode (json.dart:231:45)
    at Object.jsonEncode (json.dart:114:10)
    ...

So far we only experienced this problem with checkboxes, and have a temporary fix (PR underway). I might investigate further while I try to implement #33 .

Feature: pass custom padding to `SurveyWidget`

There is currently no way to specify the padding you want around SurveyWidget. Currently it is defaulting to EdgeInsets.all(8.0). This can make it difficult to incorporate SurveyWidget into the UI such that it matches designs.

We are wanting to pass an optional padding parameter to SurveyWidget. If this parameter is omitted, padding will continue to default to EdgeInsets.all(8.0).

Text input of type `number` should forbid invalid characters and allow decimal values

Describe the bug
Currently a text input of type number would allow characters such as a (the captured value would then become null), and at the same time double values such as 1.2 would fail the validation (with the follwing error message: {some number: {number: true}}).

To Reproduce
SurveyJs json

{
    "title": "number input issue",
    "logoPosition": "right",
    "pages": [
        {
            "name": "page1",
            "elements": [
                {
                    "type": "text",
                    "name": "some number",
                    "title": "some number",
                    "isRequired": true,
                    "inputType": "number"
                }
            ]
        }
    ],
    "showQuestionNumbers": "off"
}

SurveyJs answer

{}

Expected behavior
A text field of type number should restrict the keyboard to allow only digits and (0 or 1) decimal point(s). And decimal values (such as 1.2) shouldn't fail the number validator. This is also how the web version behaves.

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome

Missing dependency `flutter_survey_js_model` of version 0.0.2-dev.2

The build for the main branch has been failing for some time now.

pubspec.yaml on main branch reads:
flutter_survey_js_model: ^0.0.2-dev.2

Yet this version is not found on pub.dev.

P.S. I noticed several dependency updates going on under the hood, mainly around the packages like multiple_localization ^0.4.0, which seems to be resolved earlier today. I wonder if there are still remaining issues to be sorted out before we can fully upgrade to flutter 3.10.0?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.