brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
608 stars 168 forks source link

Cannot read property 'definitions' of undefined #28

Closed Vaevictus closed 8 years ago

Vaevictus commented 8 years ago

I'm trying out many of the json schema form generators out there and yours looks like the most flexible. Just testing out your demo page I am getting errors in generating a form based on my following schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "typeName": "OutgoingFileIODto",
  "additionalProperties": false,
  "required": [
    "Title",
    "Comment",
    "OwnerBoxId",
    "Status",
    "EndPoint"
  ],
  "properties": {
    "ChannelTypeName": {
      "type": "string",
      "readOnly": true
    },
    "ChannelTypeInfo": {
      "type": "string",
      "readOnly": true
    },
    "Title": {
      "type": "string"
    },
    "Comment": {
      "type": "string",
      "format": "textarea"
    },
    "Status": {
      "oneOf": [
        {
          "$ref": "#/definitions/ChannelState"
        }
      ]
    },
    "EndPoint": {
      "type": "string"
    },
    "Overwrite": {
      "type": "boolean"
    },
    "Interval": {
      "type": "integer"
    },
    "IntervalUnit": {
      "oneOf": [
        {
          "$ref": "#/definitions/TimeUnit"
        }
      ]
    },
    "DateTimeStart": {
      "type": "string",
      "format": "datetime-local"
    },
    "DateTimeStop": {
      "type": "string",
      "format": "datetime-local"
    },
    "DateTimeCreated": {
      "type": "string",
      "format": "datetime-local",
      "readOnly": true
    },
    "DateTimeLastChanged": {
      "type": "string",
      "format": "datetime-local",
      "readOnly": true
    },
    "TemporaryFolderName": {
      "type": "string",
      "readOnly": true
    },
    "OwnerBoxId": {
      "type": "integer",
      "readOnly": true
    },
    "ID": {
      "type": "integer",
      "readOnly": true
    }
  },
  "definitions": {
    "ChannelState": {
      "type": "string",
      "typeName": "ChannelState",
      "enumNames": [
        "Disabled",
        "Enabled",
        "Paused",
        "Errored"
      ],
      "enum": [
        "Disabled",
        "Enabled",
        "Paused",
        "Errored"
      ],
      "description": ""
    },
    "TimeUnit": {
      "type": "string",
      "typeName": "TimeUnit",
      "enumNames": [
        "Seconds",
        "Minutes",
        "Hours",
        "Days",
        "Weeks",
        "Months",
        "Years"
      ],
      "enum": [
        "Seconds",
        "Minutes",
        "Hours",
        "Days",
        "Weeks",
        "Months",
        "Years"
      ],
      "description": ""
    }
  }
}

the schema itself is validated as a valid json4 schema by http://jsonschemalint.com/draft4/#

Do you not fully support Json4 schemas?

Also, do you support loading externally referenced schemas using ajax and $ref?

Vaevictus commented 8 years ago

http://brutusin.org/json-forms/#11 is throwing this error on your demo page also

idelvall commented 8 years ago

Hello, thanks for reporting this. Probably @ocschwar can help us here.

Regarding your questions:

Vaevictus commented 8 years ago

The bug is on line 861

 function getDefinition(path) {
            var parts = path.split('/');
            var def = root;
            for (var p in parts) {
                if (p === 0) <<<<<HERE
                    continue;
                def = def[parts[p]];

            }
            return def;
        }

the type comparison === is returning false because p is "0" not 0 so the loop does not skip the first key/value pair of the path to the definition.

fixing that the form now renders although my selects are messed up but think that's another issue altogether

idelvall commented 8 years ago

Thanks fixed