# Enable/Disable multiple fields from two enums drop down values

**URL:** <https://jsonforms.discourse.group/t/enable-disable-multiple-fields-from-two-enums-drop-down-values/461>\
**Category:** General\
**Created:** [October 27, 2021, 9:07am UTC](https://jsonforms.discourse.group/t/enable-disable-multiple-fields-from-two-enums-drop-down-values/461 "2021-10-27T09:07:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@bala](https://jsonforms.discourse.group/u/bala)\
**Post date:** [October 27, 2021, 9:07am UTC](https://jsonforms.discourse.group/t/enable-disable-multiple-fields-from-two-enums-drop-down-values/461/1 "2021-10-27T09:07:59Z")

</div>

This is my schema

```auto
{
  "type": "object",
  "properties": {
    "fruits": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "payment": {
            "type": "string",
            "enum": [
              "none",
              "mastercard",
              "visa",
              "paypal"
            ]
          },
          "country": {
            "type": "string",
            "enum": [
              "none",
              "USA",
              "UK",
              "France",
              "Germany"
            ]
          },
		  "value":{
			"type": "string"
		  }
		  "subValue":{
			"type": "string"
		  }
        }
      }
    }
  }
}

```

In the UI schema, i plan to use “ListWithDetail”, i have requirement, where i had  
enable “value” and “subvalue” fields when “payment” is “mastercard” and “country” is “US”  
and  
disable “value” and “subvalue” fields when “payment” is “mastercard” and “country” is “none”  
How do i go on implementing rules in UI Schema for this, Thanks

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [November 3, 2021, 3:37pm UTC](https://jsonforms.discourse.group/t/enable-disable-multiple-fields-from-two-enums-drop-down-values/461/2 "2021-11-03T15:37:32Z")

</div>

Hi @bala, you can use the `options.detail` to specify a detail UI Schema containing the rules, e.g. the following should work:

```auto
{
  "type": "ListWithDetail",
  "scope": "#/properties/fruits",
  "options": {
    "detail": {
      "type": "VerticalLayout",
      "elements": [
        {
          "type": "Control",
          "scope": "#/properties/payment"
        },
        {
          "type": "Control",
          "scope": "#/properties/value",
          "rule": {
            "effect": "ENABLE",
            "condition": {
              "scope": "#/properties/payment",
              "schema": {
                "const": "mastercard"
              }
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@bala](https://jsonforms.discourse.group/u/bala)\
**Post date:** [November 10, 2021, 9:45am UTC](https://jsonforms.discourse.group/t/enable-disable-multiple-fields-from-two-enums-drop-down-values/461/3 "2021-11-10T09:45:39Z")

</div>

Thanks for the reply, in your reply the enable rule effect is applied for “value” scope, based on the scope of “payment” element. It is a simple case enabling or disabling one control or element

The question i originally asked is enabling “value” control based on “payment” and “country” control.

If payment is **'mastercard ’ and country is ‘US’** enable **value** field  
If payment is **'mastercard ’ and country is ‘None’** disable **value** field

I don’t know how to apply multiple rules to single element

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [November 10, 2021, 10:04am UTC](https://jsonforms.discourse.group/t/enable-disable-multiple-fields-from-two-enums-drop-down-values/461/4 "2021-11-10T10:04:50Z")

</div>

Hi @bala,

You can check multiple properties by referring to their parent scope, in this case it’s just `#`. You don’t need multiple rules for a single element as the provided `schema` can be arbitrarily complex and therefore cover all use cases.

It would help if you could specify your complete set of requirements, i.e. what shall happen in all the other cases?

- What shall happen if `payment` is not `mastercard`?
- What shall happen if `payment` is `mastercard` and the country is not `US` or `None`?

---

<div class="post-metadata">

**Author:** ![bala](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@bala](https://jsonforms.discourse.group/u/bala)\
**Post date:** [November 11, 2021, 11:36am UTC](https://jsonforms.discourse.group/t/enable-disable-multiple-fields-from-two-enums-drop-down-values/461/5 "2021-11-11T11:36:53Z")

</div>

What shall happen if `payment` is not `mastercard` ?  
If the payment is **not** mastercard, “value” and “sub value” are enabled.

What shall happen if `payment` is `mastercard` and the country is not `US` or `None` ?  
Then also “value” and “sub value” are enabled

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [November 19, 2021, 7:38am UTC](https://jsonforms.discourse.group/t/enable-disable-multiple-fields-from-two-enums-drop-down-values/461/6 "2021-11-19T07:38:01Z")

</div>

Hi @bala,

the following UI Schema should do the trick:

```auto
{
  "type": "ListWithDetail",
  "scope": "#/properties/fruits",
  "options": {
    "detail": {
      "type": "VerticalLayout",
      "elements": [
        {
          "type": "Control",
          "scope": "#/properties/payment"
        },
        {
          "type": "Control",
          "scope": "#/properties/country"
        },
        {
          "type": "Control",
          "scope": "#/properties/value",
          "rule": {
            "effect": "DISABLE",
            "condition": {
              "scope": "#",
              "schema": {
                "properties": {
                  "payment": {
                    "const": "mastercard"
                  },
                  "country": {
                    "const": "none"
                  }
                },
                "required": [
                  "payment",
                  "country"
                ]
              }
            }
          }
        },
        {
          "type": "Control",
          "scope": "#/properties/subValue",
          "rule": {
            "effect": "DISABLE",
            "condition": {
              "scope": "#",
              "schema": {
                "properties": {
                  "payment": {
                    "const": "mastercard"
                  },
                  "country": {
                    "const": "none"
                  }
                },
                "required": [
                  "payment",
                  "country"
                ]
              }
            }
          }
        }
      ]
    }
  }
}

```
