json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

Conditionals for arrays inside arrays #1000

Open mkormendy opened 3 years ago

mkormendy commented 3 years ago

Referencing #148,... since it was closed yet still seems like something worthwhile looking into.

See the schema below as a use case for a homekit homebridge home automation platform interface to make it easy for people to assign properties for the zones of their house based on the type of zone they are assigning. If you look at zoneActiveAtHome and zoneActiveAtNight, I would like those two items to be hidden if they do not select a specific zoneType. But not only that, I have a few more parameters (about 4 more) that I want to add to that zone that don't need to be visible if they aren't a different specific zoneType.

Because there is an array of panels with a limited number of zones (typically an array of ~6-12 zones per panel), we need to gang-up more panels together in a lot of instances. This being said, this falls in an array within an array scenario and the zones can't have hidden conditional properties within them because of this limitation in the conditionals implementation.

In this day and age, this should be solved, five years later after #148 was inquired about.

{
  "pluginAlias": "alarm system",
  "pluginType": "platform",
  "singular": true,
  "schema": {
    "name": {
      "title": "Name",
      "description": "The name that will appear in your homebridge log.",
      "type": "string",
      "default": "Alarmio",
      "required": true
    },
    "advanced": {
      "type": "object",
      "expandable": true,
      "expanded": false,
      "properties": {
        "listenerPort": {
          "title": "Listening Port (optional)",
          "description": "Force panels to send zone state changes to a specific listening port on this system (between 1000 and 65535).",
          "type": "number",
          "step": 1,
          "minimum": 1000,
          "maximum": 65535,
          "placeholder": "(default: randomized by availability)"
        },
        "listenerIP": {
          "title": "Listening IP (optional)",
          "description": "Force panels to send zone state changes to an IPV4 address that represents this system on the network. <i>In some cases, your system may have multiple network adapters registered.</i>",
          "type": "string",
          "placeholder": "(default: automatically selected)"
        },
        "discoveryTimeout": {
          "title": "Discovery Timeout (optional)",
          "description": "Provide a length of time in seconds (between 1 and 300) to allow this plugin to discover all of the Alarmio Panels on the network.",
          "type": "number",
          "step": 1,
          "minimum": 1,
          "maximum": 300,
          "placeholder": "(default: 10 seconds)"
        }
      }
    },
    "panels": {
      "description": "These are the individual Alarmio Panel module boards.",
      "type": "array",
      "orderable": true,
      "expandable": true,
      "expanded": true,
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "title": "Panel Name",
            "type": "string"
          },
          "uuid": {
            "title": "UUID",
            "type": "string",
            "readonly": true
          },
          "ipAddress": {
            "title": "IP Address",
            "type": "string",
            "placeholder": "(optional)"
          },
          "zones": {
            "description": "Customize the names and types of your zones.<br><span class='primary-text'>You need to define your zones here to create sensor and actuator accessories in HomeKit.</span>",
            "type": "array",
            "maxItems": 15,
            "expandable": true,
            "expanded": false,
            "uniqueItems": true,
            "items": {
              "type": "object",
              "properties": {
                "zoneNumber": {
                  "title": "Zone Number",
                  "type": "string",
                  "oneOf": [
                    {
                      "title": "V1/V2 & Pro: 1",
                      "enum": [1]
                    },
                    {
                      "title": "V1/V2 & Pro: 2",
                      "enum": [2]
                    },
                    {
                      "title": "V1/V2 & Pro: 3",
                      "enum": [3]
                    },
                    {
                      "title": "V1/V2 & Pro: 4",
                      "enum": [4]
                    },
                    {
                      "title": "V1/V2 & Pro: 5",
                      "enum": [5]
                    },
                    {
                      "title": "V1/V2 & Pro: 6",
                      "enum": [6]
                    },
                    {
                      "title": "V1/V2: 7 Out or Alarm",
                      "enum": ["out"]
                    },
                    {
                      "title": "Pro Only: 7",
                      "enum": [7]
                    },
                    {
                      "title": "Pro Only: 8",
                      "enum": [8]
                    },
                    {
                      "title": "Pro Only: 9",
                      "enum": [9]
                    },
                    {
                      "title": "Pro Only: 10",
                      "enum": [10]
                    },
                    {
                      "title": "Pro Only: 11",
                      "enum": [11]
                    },
                    {
                      "title": "Pro Only: 12",
                      "enum": [12]
                    },

                    {
                      "title": "Pro Only: Alarm 1",
                      "enum": ["alarm1"]
                    },
                    {
                      "title": "Pro Only: Out1",
                      "enum": ["out1"]
                    },
                    {
                      "title": "Pro Only: Alarm 2 or Out2",
                      "enum": ["alarm2_out2"]
                    }
                  ]
                },
                "zoneType": {
                  "title": "Type",
                  "type": "string",
                  "oneOf": [
                    {
                      "title": "Contact Sensor",
                      "enum": ["contact"]
                    },
                    {
                      "title": "Motion Sensor",
                      "enum": ["motion"]
                    },
                    {
                      "title": "Glass Break Sensor",
                      "enum": ["glass"]
                    },
                    {
                      "title": "Tempurature Sensor (eg. DS18B20)",
                      "enum": ["temperature"]
                    },
                    {
                      "title": "Temperature / Humidity Sensor (eg. DHT)",
                      "enum": ["temphumid"]
                    },
                    {
                      "title": "Water Leak / Rain Sensor",
                      "enum": ["water"]
                    },
                    {
                      "title": "Smoke / CO Sensor",
                      "enum": ["smoke"]
                    },
                    {
                      "title": "Alarm Arm/Disarm Switch",
                      "enum": ["armingswitch"]
                    },
                    {
                      "title": "Alarm Siren",
                      "enum": ["siren"]
                    },
                    {
                      "title": "Alarm Strobe Light",
                      "enum": ["strobe"]
                    },
                    {
                      "title": "Generic Switch",
                      "enum": ["switch"]
                    }
                  ]
                },
                "zoneLocation": {
                  "title": "Location",
                  "type": "string",
                  "placeholder": "(E.g., Living Room)"
                },
                "zoneActiveAtHome": {
                  "title": "Active in Home Mode",
                  "type": "boolean"
                },
                "zoneActiveAtNight": {
                  "title": "Active in Night Mode",
                  "type": "boolean"
                }
              }
            }
          }
        }
      }
    }
  } 
}