2016-03-01 28 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的使用情況。