I'm making a complex form for a shopping cart and I want to validate different parts of my order
object at different stages of the order process.
OrderSchema = new SimpleSchema({
itemsOrdered: {
type: [Object],
optional: false,
},
totalPrice: {
type: Number,
optional: false,
},
status: {
type: String,
optional: false
},
termsAgreed: {
type: Boolean,
optional: false
},
customerAddress: {
type: Object,
optional: false
},
stripePaymentInfo: {
type: Object,
optional: true,
blackbox: true
},
});
It's kind of a mess IMO because the different fields need to be validated differently at different stages of the order
's life cycle.
a user still in the middle of selecting products doesn't yet have
termsAgreed
,customerAddress
, orstripePaymentInfo
but I don't want validation to fail because of these two since it's still too early in the ordering process to be validating thisa user filling out their customer address doesn't need
stripePaymentInfo
yet ortermsAgreed
.etc
I need the schema to validate successfully at different stages to trigger things like enabling continue
buttons.
The problem is that autoform
always wants to use the entire schema to validate the entire object, which is fine for simple objects like Contact Me forms and such that don't have much of a lifecycle.
Is there a best practice or pattern for complex object validation at different stages of their life cycles?