Repository: mozilla-services/react-jsonschema-form (js)

Issue:
Minimum Items validation in multiple choice inputs is not working
### Prerequisites

- [X] I have read the [documentation](https://github.com/mozilla-services/react-jsonschema-form/blob/master/README.md#readme);
- [X] In the case of a bug report, I understand that providing a [SSCCE](http://sscce.org/) example is tremendously useful to the maintainers.

### Description

I'm using an array with "ui:widget": "checkboxes" to render a checkbox group in a form, and minItems=1 to validate that the user has selected at least one item. 
When a form is first rendered, we have no formData, so this is the initial state is undefined formData for the field, not an empty array.
The minItems is causing an extra 'undefined' entry to be added to the formData, which means that the validation does not work, as this entry stays here no matter what the user selects.

### Steps to Reproduce

This can be seen easily in the playground, under Arrays. Add "minItems": 1 to the multipleChoicesList section, and then delete the whole entry for multipleChoicesList from the formData section. 

Now click one of the checkboxes in the live demo and see what happens to the formData. A null entry is added after the selected values. Make it "minItems": 2, delete the formData entry and try again, and 2 null entries are added. This means that the minimum items validation does not work.

I thought that I could set a default empty array for the field, by adding default: [] in the schema, but this changes the nulls to empty arrays.

#### Expected behavior

When the user has no items selected, a minimum items validation error message should be shown.

#### Actual behavior

The minimum items error is not shown.

### Version

0.44.0


Pull request:
Fix minItems bug with multiSelect and formData
### Reasons for making this change

Check to see whether the field is a multiselect (select or checkboxes widget) before adding extra items up to minLength in the defaults.
This was causing extra, invalid items to be added into formData and breaking the minItems validation when no formData is initially present.

Fixes #534 

### Checklist

* [x] **I'm adding or updating code**
  - [x] I've added and/or updated tests
  - [x] I've updated docs if needed
  - [x] I've run `npm run cs-format` on my branch to conform my code to [prettier](https://github.com/prettier/prettier) coding style


Patch:
diff --git a/src/utils.js b/src/utils.js
index a14299d57..7359dfc2f 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -140,9 +140,13 @@ function computeDefaults(schema, parentDefaults, definitions = {}) {
 
     case "array":
       if (schema.minItems) {
-        return new Array(schema.minItems).fill(
-          computeDefaults(schema.items, defaults, definitions)
-        );
+        if (!isMultiSelect(schema, definitions)) {
+          return new Array(schema.minItems).fill(
+            computeDefaults(schema.items, defaults, definitions)
+          );
+        } else {
+          return [];
+        }
       }
   }
   return defaults;


Test patch:
diff --git a/test/ArrayField_test.js b/test/ArrayField_test.js
index b37c914a6..02b023af5 100644
--- a/test/ArrayField_test.js
+++ b/test/ArrayField_test.js
@@ -410,6 +410,40 @@ describe("ArrayField", () => {
       expect(inputs[1].value).eql("Default name");
     });
 
+    it("should not add minItems extra formData entries when schema item is a multiselect", () => {
+      const schema = {
+        type: "object",
+        properties: {
+          multipleChoicesList: {
+            type: "array",
+            minItems: 3,
+            uniqueItems: true,
+            items: {
+              type: "string",
+              enum: ["Aramis", "Athos", "Porthos", "d'Artagnan"],
+            },
+          },
+        },
+      };
+      const uiSchema = {
+        multipleChoicesList: {
+          "ui:widget": "checkboxes",
+        },
+      };
+      const form = createFormComponent({
+        schema: schema,
+        uiSchema: uiSchema,
+        formData: {},
+        liveValidate: true,
+      }).comp;
+
+      expect(form.state.formData).to.have.property("multipleChoicesList");
+      expect(form.state.formData.multipleChoicesList).to.be.empty;
+      expect(form.state.errors.length).to.equal(1);
+      expect(form.state.errors[0].name).to.equal("minItems");
+      expect(form.state.errors[0].argument).to.equal(3);
+    });
+
     it("should honor given formData, even when it does not meet ths minItems-requirement", () => {
       const complexSchema = {
         type: "object",