react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Cannot default array of objects to an empty array

Open conord33 opened this issue 7 years ago • 3 comments

Prerequisites

  • [x] I have read the documentation;
  • [x] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

When creating an array of objects using minItems there is no way to default the array to an emtpy array. If the array is empty the package with fill it with the structure of the object with all of its keys having values of undefined.

Steps to Reproduce

Shared playground

Expected behavior

When an array of objects has a default value of [] and minItems set higher than 1 it should default to an empty array with a validation error saying that the array must have at least minItems.

Actual behavior

minItems number of empty objects are injected into the array to satisfy the minItems constraint. If the object has any required fields validation with throw an error about the empty object not having that field instead of the array not having enough items.

Version

1.0.4

conord33 avatar Sep 14 '18 09:09 conord33

I think the underlying problem here is actually that the defaults weren't being applied to form correctly. The PR #1034 which was merged yesterday fixes this (you can test by checking out master and running the playground locally).

edit: just tried this running master and see this: image

@glasserc when do you think 1.0.5 will be pushed to NPM?

llamamoray avatar Sep 28 '18 11:09 llamamoray

I can probably cut a release today. I am trying to figure out how to handle #991.

glasserc avatar Sep 28 '18 16:09 glasserc

I am still getting the same issue on master 😞

conord33 avatar Oct 01 '18 11:10 conord33