json-editor icon indicating copy to clipboard operation
json-editor copied to clipboard

[Question] Hide/show property if another optional property is NOT set.

Open ajboni opened this issue 4 years ago • 3 comments

Hi! Is it possible to have a dependency rule that shows/hide a property depending if another (optional) field is NOT set ?

(non working) Example https://is.gd/zs8a1X

{
  "type": "object",
  "title": "test",
  "properties": {
    "item1": {
      "type": "object",
      "required": false,
      "properties": {
        
        "prop1": {
          "type":"string",
          "title": "Some Field"
        }
      }
    },
    "item2": {
      "type": "string",
      "required": false,
      "options": {
        "dependencies": {
          "item1": null  // ===> item1 (not required) should not be 'something'  or enabled via the checkbox.
        }
      }
    }
  }
}

Thanks

ajboni avatar Jan 10 '22 19:01 ajboni

There is indeed:

{
  "type": "object",
  "title": "test",
  "properties": {
    "item1": {
      "type": "object",
      "required": false,
      "properties": {
        "prop1": {
          "type":"string",
          "title": "Some Field"
        }
      }
    },
    "item2": {
      "type": "string",
      "options": {
        "dependencies": {
          "item1": {
            "prop1": ""
          }
        }
      }
    }
  }
}

Explanation: JSONEditor uses JSON.stringify() on the values that should be compared to. In your case you are checking for undefined and JSON.stringify("") is equal to undefined.

germanbisurgi avatar Jan 12 '22 09:01 germanbisurgi

Thanks, thats clever! Unfortunately it doesn't work with the checkbox toggle, check https://is.gd/pGuuIR

ajboni avatar Jan 12 '22 17:01 ajboni

I am working on a solution for that. Will post a PR as soon as possible.

germanbisurgi avatar Jan 14 '22 08:01 germanbisurgi