React-jsonschema-form: support for wildcard in conditional schema dependency

Created on 24 Jan 2019  路  5Comments  路  Source: rjsf-team/react-jsonschema-form

Prerequisites

Description

On the conditionals schema dependencies, how can I achieve having the conditional schema be displayed if corresponding enum array "contains" a value. Right now, it seems its only doing equality check and not supporting wildcards "*" etc.

Steps to Reproduce

For eg, in the schema, I have this property

"usageOptions": {
      "type": "array",
      "title": "Loan Usage Options",
      "items": {
        "type": "string",
        "enum": [
          "Other Home Addresses",
          "Refinance",
          "Home Improvement",
          "Education",
          "Other"
        ]
      },
      "uniqueItems": true
    },

And the conditional dependencies schema as

"dependencies": {
    "usageOptions": {
      "oneOf": [
        {
          "properties": {
            "usageOptions": {
              "items": {
                "enum": [
                  "Other"
                ]
              }
            },
            "othersDes": {
              "type": "string",
              "title": "Please describe others"
            }
          }
        }
      ]
    }
  }

Expected behavior

I want othersDes text field to appear when selected enum values "contains" Other option. So, in the multiple select list, no matter what user selects, if Other is part of selection, then, othersDes text field should display.

Actual behavior

The othersDes text field is appearing when only Other is selected.

Version

latest version "^1.2.0"

question

Most helpful comment

You can use the contains keyword for this: playground link

All 5 comments

You can use the pattern attribute to filter by a regular expression, such as other*. In this case, pattern: "Other" will suffice to make sure that the field contains the word "other." Playground link

Thanks @epicfaace , but this is showing the conditional schema when ONLY item containing 'Other' text is selected. I want to show the conditional schema even when multiple options are selected and one of the selected options is enum value Other.
screen shot 2019-01-24 at 9 25 10 pm

For example, in above scenario, it should show the conditional schema 'please describe others' text field.

You can use the contains keyword for this: playground link

Thank you so much @epicfaace . I used a combination of your suggestions to solve, and works like a charm. Here is how the dependency looks like, for anyone else facing this issue

dependencies: {
    usageOptions: {
      oneOf: [
        {
          properties: {
            usageOptions: {
              contains: {
                enum: ["Other"]
              }
            },
            othersDes: {
              type: "string",
              title: "Please describe others"
            }
          }
        }
      ]
    }
  }

This will make sure that conditional schema kicks in only when specifically, one if the enum options ( in this case Other is included the enum array.

Great, glad it works @KKS1 !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eric24 picture Eric24  路  3Comments

abhishekpdubey picture abhishekpdubey  路  3Comments

mammad2c picture mammad2c  路  3Comments

anttivikman picture anttivikman  路  3Comments

mfulton26 picture mfulton26  路  3Comments