angular2-json-schema-form icon indicating copy to clipboard operation
angular2-json-schema-form copied to clipboard

Nested array sized to 'second' array size for all nested arrays.

Open Thorski opened this issue 7 years ago • 2 comments

Issue type

I'm submitting a (check one): [X ] Bug report

Prerequisites

Before posting, make sure you do the following (check all): [X] Confirm you are using the latest versions of all necessary packages (or if not, explain why not) [X] Search GitHub for a similar issue or PR

Current behavior

Similar to Issue #78 but it seems to size according to the SECOND nested array size now.

Expected behavior

Should have different sizes for each array.

IMPORTANT: How can we reproduce your problem?

Paste below into the playground. Should have nested array sizes of 1, 3, and 2. Instead they all are of size 3 with 'undefined' entries.

{
  "schema": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "name": {
        "type": "string"
      },
      "configuration": {
        "type": "object",
        "properties": {
          "configs": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "identifier": {
                  "type": "string"
                },
                "preferences": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "tag": {
                        "type": "string"
                      },
                      "value": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
    }
  },
  "layout": [
    {
      "type": "section",
      "expandable": true,
      "title": "Configuration",
      "items": [
        {
          "key": "configuration.configs",
          "title": "Module",
          "type": "array",
          "items": [
            {
              "key": "configuration.configs[].identifier",
              "notitle": true,
              "type": "div",
              "display": "flex",
              "flex-direction": "row",
              "fxLayoutGap": "12px",
              "items": [
                {
                  "key": "configuration.configs[].identifier",
                  "flex": "1 1 100px",
                  "required": true,
                  "title": "Module Identifier"
                }
              ]
            },
            {
              "key": "configuration.configs[].preferences",
              "title": "Module Preference",
              "type": "array",
              "flex-direction": "row",
              "items": [
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "fxLayoutGap": "12px",
                  "items": [
                    {
                      "key": "configuration.configs[].preferences[].tag",
                      "flex": "1 1 100px",
                      "required": true
                    },
                    {
                      "key": "configuration.configs[].preferences[].value",
                      "flex": "1 1 100px",
                      "required": true
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "submit",
      "title": "Submit"
    }
  ],
  "data": {
    "id": "KR3",
    "name": "KR3",
    "configuration": {
      "configs": [
        {
          "identifier": "Controller 1",
          "preferences": [
            {
              "tag": "tag1",
              "value": ""
            }          ]
        },
        {
          "identifier": "Controller 2",
          "preferences": [
            {
              "tag": "tag1",
              "value": ""
            },
            {
              "tag": "tag2",
              "value": ""
            },
            {
              "tag": "tag3",
              "value": ""
            }
          ]
        },
        {
          "identifier": "Controller 3",
          "preferences": [
            {
              "tag": "tag1",
              "value": ""
            },
            {
              "tag": "tag2",
              "value": ""
            }
          ]
        }
      ]
    },
  }
}

Thorski avatar Jan 24 '18 19:01 Thorski

This is particularly bad if the size of that element is less than the maximum. Then that entry is not displayed at all! For instance if you switch Controller 2 and Controller 3 in the above example (shown below).

AND if you click the 'add' button - it shows the 3rd item (which was already there just hidden it seems).

Not sure if there is any workaround or way to make the form work with nested arrays of different sizes.

{
  "schema": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "name": {
        "type": "string"
      },
      "configuration": {
        "type": "object",
        "properties": {
          "configs": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "identifier": {
                  "type": "string"
                },
                "preferences": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "tag": {
                        "type": "string"
                      },
                      "value": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
    }
  },
  "layout": [
    {
      "type": "section",
      "expandable": true,
      "title": "Configuration",
      "items": [
        {
          "key": "configuration.configs",
          "title": "Module",
          "type": "array",
          "items": [
            {
              "key": "configuration.configs[].identifier",
              "notitle": true,
              "type": "div",
              "display": "flex",
              "flex-direction": "row",
              "fxLayoutGap": "12px",
              "items": [
                {
                  "key": "configuration.configs[].identifier",
                  "flex": "1 1 100px",
                  "required": true,
                  "title": "Module Identifier"
                }
              ]
            },
            {
              "key": "configuration.configs[].preferences",
              "title": "Module Preference",
              "type": "array",
              "flex-direction": "row",
              "items": [
                {
                  "type": "div",
                  "displayFlex": true,
                  "flex-direction": "row",
                  "fxLayoutGap": "12px",
                  "items": [
                    {
                      "key": "configuration.configs[].preferences[].tag",
                      "flex": "1 1 100px",
                      "required": true
                    },
                    {
                      "key": "configuration.configs[].preferences[].value",
                      "flex": "1 1 100px",
                      "required": true
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "submit",
      "title": "Submit"
    }
  ],
  "data": {
    "id": "KR3",
    "name": "KR3",
    "configuration": {
      "configs": [
        {
          "identifier": "Controller 1",
          "preferences": [
            {
              "tag": "tag1",
              "value": ""
            }          ]
        },
        {
          "identifier": "Controller 3",
          "preferences": [
            {
              "tag": "tag1",
              "value": ""
            },
            {
              "tag": "tag2",
              "value": ""
            }
          ]
        },
        {
          "identifier": "Controller 2",
          "preferences": [
            {
              "tag": "tag1",
              "value": ""
            },
            {
              "tag": "tag2",
              "value": ""
            },
            {
              "tag": "tag3",
              "value": ""
            }
          ]
        },
      ]
    },
  }
}

Thorski avatar Jan 30 '18 15:01 Thorski

I am facing the same issue

karthikchintala64 avatar Sep 04 '19 17:09 karthikchintala64