Json Schema Validation not working properly For Angular 2.5.2

  "type": "object",
  "properties": {
    "class": {
      "type": "string",
      "enum": ["A", "B", "C"],
      "minLength": 1
    },
    "student": {
      "type": "object",
      "properties": {
        "gender": {
          "type": "string",
          "enum": ["Male", "Female"]
        },
        "name": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  },
  "required": ["class"],
  "if": {
    "properties": {
      "class": {
        "const": "B"
      }
    }
  },
  "then": {
    "properties": {
      "student": {
        "type": "object",
        "required": ["gender", "name"]
      }
    }
  }
}

I have the above schema which i got Validated from folks at json-schema.
What problem/bug i am currently facing is

  1. When option selected is B then Gender and name field becomes required which works as expected
    but when i select option such as A and C and interact with fields Gender and name and clear them at that time also i am seeing validation errors which shouldn’t be happening since A and C shouldn’t be marking the gender and name field as required from above logic

Hi @Pranjal,

agree that sound like a bug. Did you check whether it works with JSON Forms 3.0?

I have a limitation for angular 10 so wont be able to upgrade or not planning to move angular untill now.
any workaround this for current version you suggest?

If i use custom renderrer is it possible to set state of field required based on the prevs value select using jsonFormControls? and selecting A and C shouldnt be having the above issue?

Hi @Pranjal,

The renderers we already offer use the same mechanism as custom renderers. So you have the full power of JSON Forms at your hands and could also fix the error as described above. Of course you can also then manually set the state of your field and store previous values of your field separately. We don’t store prev values automatically so you need to do this yourself in the custom renderer.

I am having the shared custom renderer for this so this become’s easy for me. I am already having state of prevs value select.

Can you please give me an example for this ? For Eg to set data for other fields Actions.update is helpfull in that scenario but for setting required field i am not aware of any state managment prop can you please highlight or share some any prop which can help me fix this.

Ohh also the asterisks are missing for the required fields for conditional Required properties how can i have this aswell. since i am having shared custom state If i try to add it the required asterisk’s ends up twice.

If i have a single custom renderer then I end up with asterisks but i’ll have to write for each and every field then which becomes tedious and not reusable. wanted to make it reusable.also the validation error end’s up coming initially which i dont want since i am using ValidateAndHide and toggling this on click of submit if there are errors with ValidateAndShow

Any “deep” customization which you want to have in all other renderers requires you to also create a custom renderer for them. It’s a common use case that consumers start with our off-the-shelf renderer sets and then create their own specialized ones, often stopping to use the off-the-shelf renderer set completely or only to derived from.