Angular-6-JSON schema form Error: Nested Arrays getControl error: Unable to find "0" item in FormGroup

867 views Asked by At

Hello I'm currently working on a project that uses JSON schema form

Keep getting the following error when using a layout for nested arrays which have recursive schema references

Nested Arrays getControl error: Unable to find "0" item in FormGroup.

Example: https://stackblitz.com/edit/angular-c1mzvk

Recursive References Example: https://hamidihamza.com/ajsf/?set=ng-jsf&example=ng-jsf-deep-ref&framework=bootstrap-4&language=en

If I do not provide a layout or set layout = ['*'], the form works perfectly. If I do provide one it's unable to render the form

No luck with the Github issue either

1

There are 1 answers

3
yatinsingla On

Here is the stackbiltz link: https://stackblitz.com/edit/angular-zvsitp

I have changed the schema to below mentioned code and I see no error in console.

schema = {
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
title: "Product Variant",
additionalProperties: false,
definitions: {
  int: {
    type: "number",
    minimum: 0,
    maximum: 10
  },
  string: {
    type: "string",
    minLength: 0
  },
  valueItem: {
    type: "object",
    properties: { value: { $ref: "#/definitions/int" } }
  },
  valueItemArray: {
    type: "array",
    items: { $ref: "#/definitions/valueItemArray" }
  },
  dtoArray: {
    type: "array",
    items: { $ref: "#/properties/staffLanguageLevelDto" }
  },

},
properties: {
  staffLanguageLevelDto: {
    type: "object",
    properties: {
      id: { $ref: "#/definitions/int" },
      staffId: {
        allOf: [
          { $ref: "#/definitions/int" },
          { maximum: 5, title: "staffId (overriden maximum)" }
        ]
      },
      languageId: {
        allOf: [
          { $ref: "#/definitions/valueItem" },
          { title: "languageId (object with custom title)" }
        ]
      },
      languageLevelId: { $ref: "#/definitions/int" },
      languageName2: {
        allOf: [
          { $ref: "#/definitions/string" },
          {
            default: "ole",
            maxLength: 3,
            title: "languageName2 (custom default & maxLength)"
          }
        ]
      },
      languageLevelName: { $ref: "#/definitions/dtoArray" }
    }
  }
}
};