I have the following Schema:
Dates.attachSchema(new SimpleSchema({
description: {
type: String,
label: "Description",
max: 50
},
start: {
type: Date,
autoform: {
afFieldInput: {
type: "bootstrap-datepicker"
}
}
},
end: {
type: Date,
autoform: {
afFieldInput: {
type: "bootstrap-datepicker"
}
}
}
}));
How can I validate that the end
date is not before start
? I am using MomentJS to handle date types, however my main problem is how I can access other attributes in the custom
function.
For instance:
end: {
type: Date,
autoform: {
afFieldInput: {
type: "bootstrap-datepicker"
}
},
custom: function() {
if (moment(this.value).isBefore(start)) return "badDate";
}
}
How can I access start
?
Furthermore, how can I validate if the start
+ end
date combination is unique, meaning there is no document saved in my database which has the exact same start
and end
date?
For the inter-field communication, you can do:
You should of course declare the
badDate
error firstRegarding the uniqueness, first of all simple schema itself does not provide uniqueness check. You should add
aldeed:collection2
for that.Furthermore, collection2 is capable of checking only a single field uniqueness. To accomplish compound indexes, you should use the
ensureIndex
syntaxEven after this, you will not be able to see the error from this compound index on your form because autoform needs to be aware that such error is existing.