【发布时间】:2015-12-27 22:21:56
【问题描述】:
我有一个通过 AutoForm 创建的表单。
就数据来源而言,我可以填写部分表格并使用:
AutoForm.getFormValues('form-id').insertDoc // returns the contents of the form
当我验证表单时,我可以:
var formValues = AutoForm.getFormValues('form-id').insertDoc;
var isValid = MyCollection.simpleSchema().namedContext("myContext").validate(formValues);
// if isValid returns true, then I enable the Submit button
我想手动将信息添加到 Autoform 用于验证和提交到集合的任何对象中,而不是填写表单的某些部分。
例如,架构中的某些数据字段根本不需要出现在表单本身中。
拿一个购物车:
ShoppingCartSchema = {
totalPrice: {
type: Number,
optional: false
},
itemsSelected: {
type: [Object],
optional: false
}
};
itemsSelected 的数据显然是通过用户在表单上输入提供的。
totalPrice 的数据不应该来自表单输入。它是在代码中生成的。
但totalPrice 在 AutoForm 将表单提交到集合之前仍需要验证为必填字段。
那么如何将totalPrice 添加到 Autoform 最终验证的对象上?
【问题讨论】: