Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(layout): array of array is missing the 2nd sub element #47

Closed
4 of 5 tasks
Mathou54 opened this issue Dec 3, 2018 · 7 comments
Closed
4 of 5 tasks

bug(layout): array of array is missing the 2nd sub element #47

Mathou54 opened this issue Dec 3, 2018 · 7 comments

Comments

@Mathou54
Copy link

Mathou54 commented Dec 3, 2018

Describe the bug
which template:

  • MaterialDesignFrameworkModule — Material Design
  • Bootstrap3FrameworkModule — Bootstrap 3
  • Bootstrap4FrameworkModule — Bootstrap 4
  • NoFrameworkModule — plain HTML
  • Other (please specify below)

A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. got to https://hamidihamza.com/Angular6-json-schema-form/
  2. past
{
  "schema": {
      "type": "object",
      "properties": {
          "value1": {"type": "string"},
          "array1": {
              "type": "array",
              "items": {
                  "type": "array",
                  "items": {
                      "type": "string"
                  }
              }
          }
      }
    
  },
  "layout": [
      {"key": "value1"},
      {"key": "array1",
          "type": "array",
          "items": [{
              "key": "array1[]",
              "type": "array",
              "items": [{
                 "key": "array1[][]",
                  "type": "string"
              }]
          }]
      }
  ],
  "data": {
      "value1": "value1",
      "array1":[["array11", "array12"], ["array21"]]
  }
}

as type.

Expected behavior
array1[0] should display the 2nd elements (array12).

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Log output covering before error and any error statements

Insert log hereCopy

Additional context
Add any other context about the problem here.

@RS-Roshi
Copy link

RS-Roshi commented Dec 3, 2018

Something is wrong with your schema..
You're saying array1 is array type its inside object is array type and in subarray there is a string object..
Array
_____subArray
______________string(inside the sub array)
And you're using layout to adjust the schema.. Layout is used to adjust the form widgets like input fields drop down.. Youre schema is invalid please get help from test examples first before writing ur schema

@Mathou54
Copy link
Author

Mathou54 commented Dec 3, 2018

But why the data I pass is marked valid? (An object containing an array of array of string.)
This means the schema is the right one (or at least the schema and data are ok, maybe the layout is wrong).

@RS-Roshi
Copy link

RS-Roshi commented Dec 5, 2018

But why the data I pass is marked valid? (An object containing an array of array of string.)
This means the schema is the right one (or at least the schema and data are ok, maybe the layout is wrong).

as by my thoughts of this library ,, layout is used to adjust the positioning and somethings like that kindly i refer you to check its given examples.

@scottux
Copy link

scottux commented Feb 14, 2019

Removing the layout definition altogether displays the form as I think you expect it to be.

@joenarus
Copy link

joenarus commented Mar 5, 2020

This problem is being caused by a tandem of these two things inside of buildLayout:
code piece 1:

var nodeValue = JsonPointer.get(jsf.formValues, newNode.dataPointer.replace(/\/-/g, '/1'));

and code piece 2:

// Add any additional default items
                if (!newNode.recursiveReference || newNode.options.required) {
                    var arrayLength = Math.min(Math.max(newNode.options.tupleItems + newNode.options.listItems, isArray(nodeValue) ? nodeValue.length : 0), newNode.options.maxItems);
                    for (var i = newNode.items.length; i < arrayLength; i++) {
                        newNode.items.push(getLayoutNode({
                            $ref: itemRefPointer_1,
                            dataPointer: newNode.dataPointer,
                            recursiveReference: newNode.recursiveReference,
                        }, jsf, widgetLibrary));
                    }
                }

Based on how this parses layouts, it goes bottom up. If you have a child array, it will create its layout first. Then when it gets to the parent array, it will use code piece 2 to add items to the parent array based on the child it already created. It only creates one version of the child, which is where code piece 1 comes in. If you create data that has two elements in the parent and the second parent item has elements in the child array, the child array of the first parent element will have the same number of items as the second element. (This is because it's replacing the dataPointer dashes with a 1 always and not 0 or a correct index).

I am currently investigating a fix for this! Will respond back soon!

@github-actions
Copy link

github-actions bot commented May 5, 2020

Stale issue

@mkormendy
Copy link

mkormendy commented Aug 31, 2020

Another issue unresolved and closed by a bot .... @hamzahamidi Can you please reopen this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants