3

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

Neil
  • 2,802
  • 8
  • 34
  • 49
  • The problem is there : key: "staffLanguageLevelDto.languageLevelName[]" bind it to correct key. – Fmerco Feb 27 '20 at 19:33
  • Could you please elaborate, I have assigned it to the right key – Neil Feb 28 '20 at 07:51
  • Your don't have definition for staffLanguageLevelDto (you are referencing staffLanguageLevelDto in dtoArray). So what yatinsingla suggested was right – Santhosh S Mar 05 '20 at 11:54
  • definitions/staffLanguageLevelDto IS present under definitions in the schema. Schema does not throw any invalid errors when validated – Neil Mar 06 '20 at 13:22

1 Answers1

0

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" }
    }
  }
}
};
yatinsingla
  • 434
  • 6
  • 13