AppliedMathematicsANU / plexus-form

A dynamic form component for react using JSON-Schema.
MIT License
134 stars 31 forks source link

Uncaught TypeError: Cannot read property 'length' of undefined with Minimal example #43

Closed sambev closed 9 years ago

sambev commented 9 years ago

I am trying to use the minimal example going in one of my projects, but am getting

Uncaught TypeError: Cannot read property 'length' of undefined Here:

    var errorClass = function(errors) {
      return (errors === null || errors.length === 0) ? '' : 'error';
    };

Which is getting called from here:

    var SectionWrapper = React.createClass({displayName: "SectionWrapper",
      render: function() {
        var level = this.props.path.length;
        var classes = [].concat('form-section',
                                (level > 0 ? 'form-subsection' : []),
                                this.props.classes || []);
        var legendClasses = [].concat(errorClass(this.props.errors) || [], //< HERE
                                      'form-section-title');

this.props looks like this:

children: Array[1]
classes: undefined
description: "Declarative pure data DSLs are the best."
errors: undefined
path: Array[0]
title: "My pretty form"

My code: (h is just a helper function for React.createElement)

// in the render
h(Form, {
    schema: {
        title      : "My pretty form",
        description: "Declarative pure data DSLs are the best.",
        type       : "object",
        properties : {
            comment: {
                title      : "Your comment",
                description: "Type something here.",
                type       : "string",
                minLength  : 1,
            }
        }
    },
    validate: validate,
    onSubmit: this.handleSubmit
})

Simply adding an errors prop on the form doesn't really do anything. Where does that prop come from and why is mine undefined in the minimal examples as well as others I have tried? Am I missing something?

odf commented 9 years ago

This has been fixed in master a while ago. I just released version 0.1.3 which includes the fix, so hopefully this will be the last we see of this issue.