[Solved] Collection2 package nesting models for autoform contract generator

Hello,

I am building form driven contract generator and what i would like to accomplish is to be able to do something like this using collection2 package

Define Person schema

Schemas.person = {
  type: Object,
  firstName: {
    type: String
  },
  lastName: {
    type: String
  },
  DOB: {
    type: Date
  }
};

Attach person schema to employment contract

let schema = {
  employer: Schemas.person,
  employeee: Schemas.person
};

Schemas.employmentContract = new SimpleSchema(schema);

And then to create contract form wizard

    <template name="step1">
        {{> quickForm schema='Schemas.employmentContract .employer' type='method' meteormethod='processContractForm' id='step1'}}
    </template>
 <template name="step2">
        {{> quickForm schema='Schemas.employmentContract.employee' type='method' meteormethod='processContractForm' id='step2'}}
    </template>

Save the data in session and in final 2nd step to validate it against schema in processContractForm server method.

My first problem is how to achieve nesting of the Schemas.person object

Second problem is how to achieve schema chunking using quickform like Schemas.employmentContract.employee

Sometimes, when you ask question. The answer just magically pops out.
The first problem can be solved like that:

Schemas.person = new SimpleSchema({
  firstName: {
    type: String
  },
  lastName: {
    type: String
  },
  DOB: {
    type: Date
  }
});


Schemas.employmentContract = new SimpleSchema({
  employer: {
    label: 'Employee',
    type: Schemas.person
  },
  employee: {
    label: 'Employer',
    type: Schemas.person
  }
});

I think i finally got it, second method i was looking for is pick() which works like that

 var nameSchema = profileSchema.pick(['firstName', 'lastName']);

So I am finally able to chunk my schema into form wizard.

Sorry for polluting the forum but sometimes to solve the problem is the best way to ask question.

1 Like