dschnelldavis / angular2-json-schema-form

Angular 2 JSON Schema Form builder
MIT License
285 stars 177 forks source link

Single item in array cause error while removing #301

Open kacperdev opened 6 years ago

kacperdev commented 6 years ago

Issue type

I'm submitting a (check one): [X] Bug report [ ] Feature request [ ] Regression (something that used to work, but stopped working in a newer version) [ ] Support request [ ] Documentation issue or request

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 [X] If submitting a Support request, also search Stack Overflow for similar issues Note: Please cross-post GitHub support requests to Stack Overflow, and include a link in your GitHub issue to your Stack Overflow question. We do currently respond to support requests on GitHub, but we eventually expect to stop, and will then refer all support questions exclusively to Stack Overflow.

Current behavior

Hi, i'm currently working on some form based on json schema. My json is more complex, but I managed to reproduce that error on your site https://angular2-json-schema-form.firebaseapp.com/. When Im trying to remove one item from array it gives me an error. Code: { "schema": { "title": "Comment", "type": "object", "required": [ "comments" ], "properties": { "comments": { "type": "array", "minItems": 1, "items": { "type": "object", "properties": { "name": { "title": "Name", "type": "string" } } } } } }, "form": [ { "key": "comments", "items": [ "comments[].name" ] }, { "title": "OK", "type": "submit", "style": "btn-info" } ] }

It's based on one of your examples. The error is: TypeError: "this.getFormControlGroup(...).removeAt is not a function". I'm using Bootstrap 3.

Expected behavior

It should remove one of item from array.

IMPORTANT: How can we reproduce your problem?

{ "schema": { "title": "Comment", "type": "object", "required": [ "comments" ], "properties": { "comments": { "type": "array", "minItems": 1, "items": { "type": "object", "properties": { "name": { "title": "Name", "type": "string" } } } } } }, "form": [ { "key": "comments", "items": [ "comments[].name" ] }, { "title": "OK", "type": "submit", "style": "btn-info" } ] }

Environment

OS name & version: Windows 10 Browser name & version: Firefox 61.0.1 Angular version: 5 Angular JSON Schema Form version(s): 0.7.0-alpha.1 Other relevant software or packages:

Any other relevant information

shangzhouwan commented 4 years ago

This will work fine: `{ "schema": { "title": "Comment", "type": "object", "required": [ "comments" ], "properties": { "comments": { "type": "array", "maxItems": 2, "items": { "type": "object", "properties": { "name": { "title": "Name", "type": "string" } }, "required": [ "name" ] } } } }, "form": [

{ "key": "comments",
  "add": "New",
  "style": { "add": "btn-success" },
  "items": [{
     "items": [{
      "key":"comments[].name"
  }
  ]
  }
  ]
},
{ "title": "OK",
  "type": "submit",
  "style": "btn-info"
}

] }`