Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to have only the dependent fields when the primary field is set to true #2955

Closed
1 task done
Michael-Xie opened this issue Jul 22, 2022 · 1 comment
Closed
1 task done
Assignees
Labels
bug if-then-else Issues related to handling JSON Schema if/then/else question

Comments

@Michael-Xie
Copy link

Prerequisites

What theme are you using?

material-ui

What is your question?

Hi,

Currently, I am encountering an issue where I have a toggle. When it is selected, it would display more fields to fill out. However, when the toggle is unselected, the dependent field values are retained.

What can be done to resolve this?

Current Schema:

{
	"title": "Visual (Top Level) Schema",
	"description": "Settings for individual visualizations",
	"type": "object",
	"properties": {
		"locationGroupSettings": {
			"type": "object",
			"description": "Settings for the location groups",
			"properties": {
				"isMultipleLocationGroups": {
					"type": "boolean",
					"description": "Does this report show data for one locationGroup or multiple locationGroups",
					"default": false
				},
				"include": {
					"type": "array",
					"description": "List of locationGroups to include",
					"items": {
						"type": "string"
					}
				}
			},

			"if": {
				"properties": { "isMultipleLocationGroups": { "const": true } }
			},
			"then": {
				"properties": {
					"selectionMin": {
						"type": "integer",
						"description": "Minimum number of locationGroups to show"
					},
					"selectionMax": {
						"type": "integer",
						"description": "Maximum number of locationGroups to show"
					}
				}
			}
		}
}

Updated schema that I have tried:
based on: https://react-jsonschema-form.readthedocs.io/en/v1.8.1/dependencies/

{
	"title": "Visual (Top Level) Schema",
	"description": "Settings for individual visualizations",
	"type": "object",
	"properties": {
		"locationGroupSettings": {
			"type": "object",
			"description": "Settings for the location groups",
			"properties": {
				"isMultipleLocationGroups": {
					"type": "boolean",
					"description": "Does this report show data for one locationGroup or multiple locationGroups",
					"default": false
				},
				"include": {
					"type": "array",
					"description": "List of locationGroups to include",
					"items": {
						"type": "string"
					}
				},
				"dependencies": {
					"isMultipleLocationGroups": {
						"oneOf": [
							{
								"properties": {
									"isMultipleLocationGroups": { "const": false }
								}
							},
							{
								"properties": {
									"isMultipleLocationGroups": { "const": true },
									"selectionMin": {
										"type": "integer",
										"description": "Minimum number of locationGroups to show"
									},
									"selectionMax": {
										"type": "integer",
										"description": "Maximum number of locationGroups to show"
									},
									"required": ["selectionMin", "selectionMax"]
								}
							}
						]
					}
				}
			}
		}
}

error from above:

Unsupported field schema for field root_locationGroupSettings_dependentSchemas: Unknown field type undefined.

{
  "isMultipleLocationGroups": {
    "oneOf": [
      {
        "properties": {
          "isMultipleLocationGroups": {
            "const": false
          }
        }
      },
      {
        "properties": {
          "isMultipleLocationGroups": {
            "const": true
          },
          "selectionMin": {
            "type": "integer",
            "description": "Minimum number of locationGroups to show"
          },
          "selectionMax": {
            "type": "integer",
            "description": "Maximum number of locationGroups to show"
          },
          "required": [
            "selectionMin",
            "selectionMax"
          ]
        }
      }
    ]
  }
}
@Michael-Xie Michael-Xie added needs triage Initial label given, to be assigned correct labels and assigned question labels Jul 22, 2022
@heath-freenome heath-freenome added bug if-then-else Issues related to handling JSON Schema if/then/else and removed needs triage Initial label given, to be assigned correct labels and assigned labels Dec 16, 2022
@heath-freenome
Copy link
Member

This is a duplicate of #2720, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug if-then-else Issues related to handling JSON Schema if/then/else question
Projects
None yet
Development

No branches or pull requests

4 participants