Skip to content

Conditionals attributes are not removed after the condition is unmatched #56

@sandrina-p

Description

@sandrina-p

Problem

The following example is about description, but this happens with any conditional attribute (title, minimum, etc).

Given a form that asks for two fields is_full_time (yes/no) and hours (number). If yes is selected, then it shows a description warning about the maximum hours.

The JSON Schema is the following:

{
  "properties": {
    "is_full_time": {
      "type": "string",
      "title": "Is full time",
      "oneOf": [{ "const": "yes", "title": "Yes" }, { "const": "no", "title": "No" }]
    },
    "hours": { "type": "number", "title": "Hours per day" }
  },
  "allOf": [
    {
      "if": {
        "properties": { "is_full_time": { "const": "yes" } },
        "required": ["is_full_time"]
      },
      "then": {
        "properties": {
          "hours": {
            "description": "We recommend no more than 8 hours."
          }
        }
      }
    }
  ]
}

Steps to reproduce:

  1. In the playground add the schema above.
  2. Select Yes, the description shows up.
  3. Select No. The description should disappear but it remains 🐛
image

For this scenario, a workaround could be to undo the value by set description: "" in the else statement, like this:

"else": {
  "properties": {
    "hours": {
      "description": ""
     }
   }
}

But this ain't possible for every attribute. For example, if you set const: 10, there's no way to "undo" it. Same for any other type of validation.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions