2016-03-01 45 views
0

错误消息:错误试图流星更新使用自动窗体与Schema文档

"Uncaught Error: After filtering out keys not in the schema, your modifier is now empty"

使用与流星collection2和简单模式自动窗体。 架构:

Injuries = new Mongo.Collection('injuries'); 

Rehab = new SimpleSchema({ 
    exercise: { 
    type: String, 
    label: "Rehab Exercise" 
    }, 
    sets: { 
    type: Number, 
    label: "Sets" 
    }, 
    duration: { 
    type: Number, 
    label: "Set Duration (in Minutes)" 
    }, 
    date: { 
    type: String, 
    label: "Date of Rehab Exercise" 
    }, 
    rehabnotes: { 
    type: String, 
    label: "Notes: i.e. 70% Intensity During Sprints", 
    max: 200 
    }, 
    injuryid:{ 
    type: String, 
    } 
}); 

Injuries.attachSchema(new SimpleSchema({ 
    player: { 
    type: String, 
    label: "Player", 
    max: 50 
    }, 
    injury: { 
    type: String, 
    label: "Injury" 
    }, 
    notes: { 
    type: String, 
    label: "Notes", 
    max: 200 
    }, 
    injurydate: { 
    type: Date, 
    label: "Date of Injury", 
    }, 
    rehab: { 
    type: [Rehab], 
    optional: true 
    } 
})); 

和表单代码的模板:

{{#autoForm collection="Injuries" schema="Rehab" id="insertRehabForm" type="update"}} 
      <fieldset> 

       {{> afQuickField name='exercise' options=options}} 
       {{> afQuickField name='sets'}} 
       {{> afQuickField name='duration'}} 
       {{> afQuickField name='date'}} 
       {{> afQuickField name='rehabnotes' rows=6}} 

      </fieldset> 
      <button type="submit" class="btn btn-primary">Insert</button> 
       {{/autoForm}} 

我可以插入文件,只是在主页上了自动精细,使用的单个文档页面我这个自定义窗体在提交时收到错误。

我有一个集合挂钩在提交之前建立起来,但是这看起来只是一个架构错误,或许我在原始Injuries架构上设置的Rehab阵列正在搞砸了这个?我为此所做的搜索都是关于模式中的“Type”参数与预期内容不匹配的,但我在这里检查了它们,并且它们看起来不错。建议?

回答

1

基于自动窗体的docs:需要schema属性如果collection属性未设置,但是,即使collection设置自动窗体仍将使用提供schema属性产生(仅适用于QuickForm)和验证表单(适用于AutoForm和QuickForm)。

你的情况发生了什么事是,由于设置了两个属性(schemacollection),自动窗体首先验证对Rehab架构的表单字段,当它成功了,它试图插入这些字段的值(锻炼,套,持续时间,日期,康复)到你的Injuries集合,它没有自己的模式(它只有玩家,伤害,笔记,injurydate和修复)这些键。

根据您的要求,似乎将AutoForm类型设置为update-pushArray是最好的解决方案。检查docsexample的使用情况。