ismaelga / react-json-editor

A dynamic form component for react using JSON-Schema.
https://ismaelga.github.io/react-json-editor
MIT License
225 stars 42 forks source link

Uncaught TypeError: normalizer[type] is not a function #2

Closed haf closed 8 years ago

haf commented 8 years ago

Using latest from npm

React.createClass.normalize @   react-json-editor.js:924
React.createClass.handleChange  @   react-json-editor.js:934
LinkedValueUtils.executeOnChange    @   index.js:13356
_handleChange   @   index.js:14446
ReactErrorUtils.invokeGuardedCallback   @   index.js:4835
executeDispatch @   EventPluginUtils.js:93
executeDispatchesInOrder    @   EventPluginUtils.js:116
executeDispatchesAndRelease @   EventPluginHub.js:57
executeDispatchesAndReleaseTopLevel @   EventPluginHub.js:68
forEachAccumulated  @   index.js:4941
EventPluginHub.processEventQueue    @   EventPluginHub.js:273
runEventQueueInBatch    @   ReactEventEmitterMixin.js:32
ReactEventEmitterMixin.handleTopLevel   @   ViewportMetrics.js:2
handleTopLevelWithoutPath   @   ReactEventListener.js:107
handleTopLevelImpl  @   ReactEventListener.js:87
Mixin.perform   @   Transaction.js:150
ReactDefaultBatchingStrategy.batchedUpdates @   ReactDOMComponent.js:1
batchedUpdates  @   ReactUpdates.js:108
ReactEventListener.dispatchEvent    @   index.js:15539

Repro JSON schema:

  const minSchema = {
    title      : "Repro Form",
    description: "Repro for error",
    type       : "object",
    properties : {
      selection: {
        "title": "Choose Category",
        "type": "object",
        "properties": {
          "mainCategory": {
            "title": "Choose the main category",
            "type": "string",
            "enum": [
              "-",
              "other"
            ],
            "enumNames": [
              "Select one of the below",
              "Misc"
            ]
          }
        },
        "oneOf": [
          {},
          {
            "properties": {
              "mainCategory": {
                "enum": [
                  "misc"
                ]
              },
              "people": {
                "title": "Misc Category",
                "type": "enum",
                "enum": [
                  "a",
                  "b",
                  "c"
                ],
                "enumNames": [
                  "Something",
                  "Something else",
                  "A third option"
                ]
              }
            }
          }
        ],
        "x-hints": {
          "form": {
            "selector": "mainCategory"
          }
        }
      }
    }
  };

Choose the third option in the form to reproduce.

ismaelga commented 8 years ago

"type": "enum" is what's causing the error here. When you use enum, you usually want to set it as type "string", as that's what will be on the output.

I guess in a future version we could throw a error message that describes possible problems with user's schema.

Here is how your schema should look like. I also changed the mainCategory enum values, to make "misc" a valid value.

{
    title: "Repro Form",
    description: "Repro for error",
    type: "object",
    properties : {
      selection: {
        "title": "Choose Category",
        "type": "object",
        "properties": {
          "mainCategory": {
            "title": "Choose the main category",
            "type": "string",
            "enum": [
              "-",
              "misc"
            ],
            "enumNames": [
              "Select one of the below",
              "Misc"
            ]
          }
        },
        "oneOf": [
          {},
          {
            "properties": {
              "mainCategory": {
                "enum": [
                  "misc"
                ]
              },
              "people": {
                "title": "Misc Category",
                "type": "string",
                "enum": [
                  "a",
                  "b",
                  "c"
                ],
                "enumNames": [
                  "Something",
                  "Something else",
                  "A third option"
                ]
              }
            }
          }
        ],
        "x-hints": {
          "form": {
            "selector": "mainCategory"
          }
        }
      }
    }
  }
haf commented 8 years ago

Thank you, that worked! Any chance of a better error message?

ismaelga commented 8 years ago

Sure. I will probably make it throw an error when the schema as an invalid type. I think that makes sense and is the expected behaviour.

haf commented 8 years ago

Can I add a third level, e.g. misc.a.third?

I haven't been able to at all. Neither with "x-hints": { "form": { "selector": "peopleCategory" } } nor with enum + array position.