1

I have an alpaca schema with an array of conditional dependencies. Each value in the array has a known prefix. Instead of using an array, is it possible to use a function/conditional that checks a value in a certain field to determine if that value has the known prefix and results in the dependent field being shown?

This question (conditionally require a field) is related to the problem I'm facing (how to get and check the value of a field in a function).

Note: One site may be categorised in more than one type, hence the TypePrefix0 on the value.

This is the code in question, as it currently stands:

"schema": {
  "properties": {
    "tpl": { "type":"string" }, 
    "site": { // optionTree
      "type":"string",
        "title":"Site",
        "required": true
    },                           
    "sourceType": {
      "type":"string",
      "title":"Source Type",
      "enum":['area','group'],
    },
    "dataType": {
      "type":"string",
      "title":"Data Type",
      "enum":['people','vehicles', '*']
    },
  },
  "dependencies": {
    "dataType": ["sourceType", "site"]
  }
},
"options": {
  "fields: { // reduced to relevant parts
    "dataType": {
      "dependencies: {
        "sourceType": "group",
        // site values shown here are not actual values used in production
        "site": ["TypePrefix0.site0", "TypePrefix0.site1", "TypePrefix0.site2", /*...*/] 
        // how do/can I replace the array with a function/condition:
        // (site.value.startsWith("TypePrefix0.")) : true
      }
    }
  }
}
Agi Hammerthief
  • 2,114
  • 1
  • 22
  • 38
  • Although you have solved this, I found a solution to your linked question so that might be helpful: https://stackoverflow.com/a/51819557/2263631 – Script47 Aug 13 '18 at 10:04

1 Answers1

0

Rather than use an optiontree control, split it into three select controls. (The first one is the site type. The other two are each sites of a specific type.) Make the second and third selects depend on specific values of the first one. That way, you do away with prefixes in the values of the second and third select controls.

Agi Hammerthief
  • 2,114
  • 1
  • 22
  • 38