rstgroup / react-components-form

React components form give you posibility to create forms with schema validation using "form-schema-validation".
https://rstgroup.gitbooks.io/react-components-form/
MIT License
30 stars 15 forks source link

Error when attaching a model to form and submitting #58

Closed GuillaumeExia closed 6 years ago

GuillaumeExia commented 6 years ago

Hello,

I'm encountering a problem with a form, let me explain:

My form structure looks like this:

{
  name:
  firstname:
  description: {
    short_desc:
    long_desc:
 }
  birthdate:
}
<Form
   schema={schema}
   model={this.model}
   onSubmit={this.sendForm}
   eventsEmitter={this.eventsEmitter}
>

So I have attached a schema which describes all my fields, and my main schema contains a nested schema (through and ObjectField). I tried to attach a model to my form but when I am submitting I get this error :

VM36297 24:1 Uncaught TypeError: t.messages.notDefinedKey is not a function at eval (VM36297 24:1) at Array.forEach ()

I can't find where this could come from, maybe you will have a clue to help me debug this?

Thanks.

GuillaumeExia commented 6 years ago
mprzodala commented 6 years ago

Please use this schemas:

const descriptionSchema = new Schema({
    short_desc: {
        type: String,
    },
    long_desc: {
        type: String,
    }
});

const schema = new Schema({
    name: {
        type: String,
    },
    firstname: {
        type: String,
    },
    description: {
        type: descriptionSchema,
    },
    birthdate: {
        type: Date,
    },
});

This error inform about key that is not defined in schema. I think you have some key in model that you dont have in schema.

 Uncaught TypeError: t.messages.notDefinedKey 

You can use third argument of schema contructor to disable not defined key validation.

const descriptionSchema = new Schema({
    short_desc: {
        type: String,
    },
    long_desc: {
        type: String,
    }
}, false, false);

const schema = new Schema({
    name: {
        type: String,
    },
    firstname: {
        type: String,
    },
    description: {
        type: descriptionSchema,
    },
    birthdate: {
        type: Date,
    },
}, false, false);
mprzodala commented 6 years ago

@GuillaumeExia could you check ?