question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fields are still flagging as required even if the OneOf conditional returns false

See original GitHub issue

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

My form is quite complex and features many select boxes with OneOf dependencies. However even when one of them is attributed to false (i.e. no other fields are dependent on the selected option) the form still throws an error thinking that the fields only displayed for another option are still required to continue the form.

Steps to Reproduce

  1. Create a select box with a OneOf dependency
  2. Choose an option that requires another set of values to be filled and required

Expected behavior

The required fields should be ignored if the dependent option is NOT chosen previously.

Actual behavior

Form throws an error thinking that the fields are required even though they are not visible.

Version

1.0.4

Here is a snippet of the JSON I used to determine which fields are required when a specific option is chosen:

"1.11": {
          "type": "object",
          "title": "",
          "properties": {
            "1.11.1": {
              "type": "string",
              "title": "Are you acting on behalf of the PLH (e.g. the agent)",
              "default": "No",
              "enum": [
                "No",
                "Yes"
              ]
            }
          },
          "dependencies": {
            "1.11.1": {
              "oneOf": [
                {
                  "properties": {
                    "1.11.1": {
                      "enum": [
                        "No"
                      ]
                    }
                  }
                },
                {
                  "properties": {
                    "1.11.1": {
                      "enum": [
                        "Yes"
                      ]
                    },
                    "1.11.2": {
                      "type": "object",
                      "title": "Other Proposed License Holder (PLH) Details",
                      "properties": {}
                    },
                    "1.11.3": {
                      "type": "object",
                      "title": "",
                      "description": "If this application is being dealt with by a person who is not the PLH, please provide contact details below.",
                      "required": [
                        "1.11.3.1"
                      ],
                      "properties": {
                        "1.11.3.1": {
                          "type": "string",
                          "title": "Name"
                        },
....

In the schema.json:

"1.11": {
      "1.11.1": {
        "ui:widget": "selectBoxWidget"
      },

As you can see, if “Yes” is chosen on the select option, the field 1.11.3.1 (name) is required. However, this should be completely irrelevant if the user chooses “No” on the select box, but the schema still clocks it as "required’.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
epicfaacecommented, Sep 12, 2019

No updates since then, although contributions are welcome to fix the issue.

1reaction
fabri86commented, Feb 5, 2019

In general, just to explain you better my thoughts, I see from you example oneOf the behaviour is from the user’s perspective wierd.

oneof

As a user who does not select the option 2, I would rather not be interested in getting a validation error for a require field which I do not even see (ipsum), but just the filed I see (for lorem indeed). I only would like to get validation errors for the form I have in front of me. Forking the repo and trying to debug your code, I also noticed that the MultiSchemaField class (AnyOfField component) is responsible for handling both anyOf and oneOf constructs… which gives me some feeling that at the moment the case I am discussing is not maybe handled … correct me please if I am wrong… or if I am not giving to the schema the correct structure…

Thanks in advance for replying

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Schema conditional: field is required based on value of ...
I'm trying to implement this condition: field is required based on value of another field i.e. if request with "index":"true" exists then ...
Read more >
Conditionals with if/else & Booleans | AP CSP (article)
Our program is guaranteed to always go down one of the two paths: either the condition is true and it goes down the...
Read more >
Use conditional formatting to highlight information
Conditional formatting can help make patterns and trends in your data more apparent. To use it, you create rules that determine the format...
Read more >
API - esbuild
There are two main API calls in esbuild's API: transform and build. ... If needed, the working directory that esbuild uses can be...
Read more >
Equality (==) - JavaScript - MDN Web Docs
Unlike the strict equality operator, it attempts to convert and ... If either operand is NaN , return false ; so, NaN is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found