Conditionally visible properties in perspective module

I am building a perspective module and I have a property I need to make visible only when a property elsewhere in the tree is true but I can’t figure out how to reference it. As an example, I have this tree:

object1
    prop1
object2
    prop2

So I need prop2 to only be visible in the designer when prop1 is true. I’ve tried “…object1.prop1” and “/object1.prop1” as references but neither work. Does this only work with properties on the same level or is there a way to correctly set this reference?

I don’t think the visibleWhen validator supports walking back up indirect references, from a scan of the code. It might work on object2.prop1, like this, but I’m not sure if it will walk down like that. In our codebase, the only examples I could find are direct sibling references. It looks like theoretically something like property: object2, equals: {"prop1": true} would be the way to do this, but I’m pretty sure there’s a bug in our code.

{
  "object1": {
    "type": "object",
    "properties": {
      "prop1": {
        "type": "boolean"
      }
    }
  },
  "object2": {
    "type": "object",
    "properties": {
      "prop2": {}
    },
    "visibleWhen": {
      "property": "object1.prop1",
      "equals": true
    }
  }
}

I figured that might be the case given all I’d seen were siblings affecting each other. Thank you for taking the time to look. If it means re-arranging the tree that’s no huge deal

1 Like

For what it’s worth, I filed a ticket to check on supporting objects as the equals reference. I can’t guarantee it’ll get accepted, but it seems reasonable.