0
votes

I'm have some simple schema which I'm using with autoform:

Schemas.studentRecord = new SimpleSchema({
    'common.FName': {       // note that this field is nested
        type: String,
        optional: false,
        label: "First Name",
        max: 50
    }
});

Inserting a document using this schema works fine. Updating it does too. The problem is that when I'm nesting data the optional: false validation is not running, it's just ignored - meaning I can insert empty documents. However use the following schema without nesting it works:

Schemas.studentRecord = new SimpleSchema({
    'commonFName': {       // note that this field is no longer nested
        type: String,
        optional: false,
        label: "First Name",
        max: 50
    }
});

So my question is, can I validate nested data or must I keep it unstructured for validation?

1

1 Answers

1
votes

Solution was to include 'common' as part of the schema:

'common': {
 type: Object
}