autoform-schema-utils
Simple utilities for merging autoform options into a simple schema.
To install:
meteor add wesleyfsmith:autoform-schema-utils
When working with autoform, it's common to start sticking autoform config options into your schema:
1Practices = new Mongo.Collection('practices'); 2 3Practices.attachSchema(new SimpleSchema({ 4 name: { 5 type: String 6 }, 7 employees: { 8 type: [String], 9 optional: true, 10 autoform: { 11 omit: true 12 } 13 }, 14 createdAt: { 15 type: Date, 16 defaultValue: new Date(), 17 autoform: { 18 omit: true 19 } 20 } 21})); 22
This is weird, because usually your collection schemas are included on the server and the client, and it's strange to have UI code in the middle of your schema. With this library you can run on the client:
1const autoFormOptions = { 2 employees: { 3 omit: true 4 }, 5 createdAt: { 6 omit: true 7 } 8}; 9 10Practices.simpleSchema().addAutoFormOptions(autoFormOptions);
Now you can keep your schema clean, and keep your separation of concerns intact. This library takes those autoFormOptions object, then attaches it the simple schema with the autoform nested field.
Forcing fields to be required
Sometimes you want to make fields optional on your schema, but once the user goes to update those fields you want to force them to fill out all the fields in the form. This function will make all of your fields required on the client only.
This is most likely useful if you want to require fields with autoform on the client, but want to keep the fields optional in your schema.
1Practices.simpleSchema().forceRequired();
You can undo making the fields required at any time:
1Practices.simpleSchema().undoForceRequired();