Change data schema dynamically

Hello there,

I would like to know if it this functionality exists or if there is intention to add this functionality in future and if not, what are reasons to not to do that.

Functionality: (React, Material)
Let’s use this schema for our data:

const schema = {
  type: 'object',
  properties: {
    flag: {
      type: 'boolean',
    },
    myEnum: {
      type: 'string',
      enum: ['none','1', '2'],
      default: 'none',
    },
  },
  anyOf: [
    {
      if: {
        properties: {
          flag: {
            const: true
          }
        }
      },
      then: {
        properties: {
          myEnum: {
            type: 'string',
            enum: ['none', '1', '2', '3'],
            default: 'none',
          },
        }
      }
    },
  ]
};

UI schema is not important in this case, just casual view.

Based on this schema by default, as a user I would like to choose from dropdown one of myEnum values [‘none’,‘1’, ‘2’].
Later on, when I change flag value to true, I would like to be able to choose from myEnum values [‘none’,‘1’, ‘2’, ‘3’].
Later on, when I change flag value to false, I would like to be able to choose only from myEnum values [none, 1, 2] and my selected value would be default again.

Thank you.

Hi @OndrejPontes,

At the moment we don’t support if/then except for validating use cases, e.g. setting maximum values. The reason for this is that JSON Schema is very flexible here and supporting this feature generically is a lot of work.

However JSON Forms is very flexible, so you can easily add a custom enum renderer which is able to look into if/then as you specify them in your schema and behaves like you outlined.