Repository: mozilla-services/react-jsonschema-form
Pull request #775 (2017-11-23 12:56:48)

Fix onAddClick signature in ArrayFieldTemplate
### Reasons for making this change

According source code `onAddClick` is not returning function as specified in the documentation.
https://github.com/mozilla-services/react-jsonschema-form/blob/master/src/components/fields/ArrayField.js#L224


### Checklist

* [x] **I'm updating documentation**
  - [x] I've checked the rendering of the Markdown text I've added
  - [ ] If I'm adding a new section, I've updated the Table of Content
* [ ] **I'm adding or updating code**
  - [ ] I've added and/or updated tests
  - [ ] I've updated docs if needed
  - [ ] I've run `npm run cs-format` on my branch to conform my code to [prettier](https://github.com/prettier/prettier) coding style
* [ ] **I'm adding a new feature**
  - [ ] I've updated the playground with an example use of the feature


edi9999: Good catch !

Patch:
diff --git a/README.md b/README.md
index ecf859c25..47d1e6990 100644
--- a/README.md
+++ b/README.md
@@ -890,7 +890,7 @@ The following props are passed to each `ArrayFieldTemplate`:
 - `disabled`: A boolean value stating if the array is disabled.
 - `idSchema`: Object
 - `items`: An array of objects representing the items in the array. Each of the items represent a child with properties described below.
-- `onAddClick: (event) => (event) => void`: Returns a function that adds a new item to the array.
+- `onAddClick: (event) => void`: A function that adds a new item to the array.
 - `readonly`: A boolean value stating if the array is read-only.
 - `required`: A boolean value stating if the array is required.
 - `schema`: The schema object for this array.
diff --git a/src/components/fields/SchemaField.js b/src/components/fields/SchemaField.js
index 4c9b109cb..0b3a0aeac 100644
--- a/src/components/fields/SchemaField.js
+++ b/src/components/fields/SchemaField.js
@@ -8,6 +8,7 @@ import {
   getUiOptions,
   isFilesArray,
   deepEquals,
+  getSchemaType,
 } from "../../utils";
 import UnsupportedField from "./UnsupportedField";
 
@@ -29,7 +30,8 @@ function getFieldComponent(schema, uiSchema, idSchema, fields) {
   if (typeof field === "string" && field in fields) {
     return fields[field];
   }
-  const componentName = COMPONENT_TYPES[schema.type];
+
+  const componentName = COMPONENT_TYPES[getSchemaType(schema)];
   return componentName in fields
     ? fields[componentName]
     : () => {
diff --git a/src/utils.js b/src/utils.js
index d57ab7761..ec0033284 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -62,8 +62,16 @@ export function getDefaultRegistry() {
   };
 }
 
+export function getSchemaType(schema) {
+  let { type } = schema;
+  if (!type && schema.enum) {
+    type = "string";
+  }
+  return type;
+}
+
 export function getWidget(schema, widget, registeredWidgets = {}) {
-  const { type } = schema;
+  const type = getSchemaType(schema);
 
   function mergeOptions(Widget) {
     // cache return value as property of widget for proper react reconciliation


Test patch:
diff --git a/test/StringField_test.js b/test/StringField_test.js
index e25af5b4b..ef65f72da 100644
--- a/test/StringField_test.js
+++ b/test/StringField_test.js
@@ -191,6 +191,16 @@ describe("StringField", () => {
       expect(node.querySelectorAll(".field select")).to.have.length.of(1);
     });
 
+    it("should render a string field for an enum without a type", () => {
+      const { node } = createFormComponent({
+        schema: {
+          enum: ["foo", "bar"],
+        },
+      });
+
+      expect(node.querySelectorAll(".field select")).to.have.length.of(1);
+    });
+
     it("should render a string field with a label", () => {
       const { node } = createFormComponent({
         schema: {