Conditional Datasets fields

Sometimes you need to have a selector and display some fields depending on this selector. You can now add a conditional attribute which will check for your selector (list) value.

First define your datatypes and add a "list" object on it then add "if" attribute to your fields.

Fields with "bank" in the "if" attribute will appear here

And here only fields withe the "paypal" key will be displayed here

As you can see, it's easy to set a bunch of attributes depending a choice on a select box.

{
  "model": [
    { 
      "r": true, "c": "1-1", "n": "payout_type", "t": "list", "j": "joi.string().required()", "l": "Type",
      "d": [["bank", "Bank"], ["paypal", "Paypal"]]
    },
    { 
      "r": true, "c": "1-1", "n": "iban", "t": "string", "j": "joi.any()", "l": "IBAN",
      "if": ["payout_type", "bank"] 
    },
    { 
      "r": true, "c": "1-1", "n": "swift", "t": "string", "j": "joi.any()", "l": "SWIFT",
      "if": ["payout_type", "bank"] 
    },
    { 
      "r": true, "c": "1-1", "n": "email", "t": "string", "j": "joi.any()", "l": "Email", 
      "if": ["payout_type", "paypal"] 
    }
  ],
  "columns": [{ "name": "payout_type" }, { "name": "iban" }, { "name": "swift" }, { "name": "email" }]
}

Leave a comment