2015-11-05 127 views
1
{{#autoForm schema="schema" id="submitoffer" type="method" meteormethod="submitoffer"}} 
     {{> afQuickField name="startLocation"}} 
     <input id="date" type="text" class="form-control datepicker"> 
     <input id="departureTime" type="text" class="form-control timepicker"> 
     <input id="returnTime" type="text" class="form-control timepicker"> 
     {{> afQuickField name="seats" type="number"}} 
     <button type="submit" class="btn btn-primary">Offer lift</button> 
    {{/autoForm}} 

我希望能夠使用的日期,departureTime和returnTime輸入(這是pickadate.js實現。然而,當我提交表單到服務器,這些投入是。不拿起作爲表單的一部分,我怎麼能要求他們輸入以及與自動窗體提交他們添加自定義輸入字段的自動窗體流星

回答

1

你可以使用afFieldInput元素並在架構設置class屬性

?例如:

<body> 
    {{#autoForm collection="Offers" id="submitoffer" type="insert"}} 
     {{> afQuickField name="startLocation"}} 
     {{> afFieldInput name="date"}} 
     {{> afFieldInput name="departureTime"}} 
     {{> afFieldInput name="returnTime"}} 
     {{> afQuickField name="seats"}} 
     <button type="submit" class="btn btn-primary">Offer lift</button> 
    {{/autoForm}} 
</body> 

if (Meteor.isClient) { 
    Template.body.onRendered(function() { 
     $('.datepicker').pickadate(); 
     $('.timepicker').pickatime(); 
    }); 
} 

Offers = new Mongo.Collection("offers"); 

Offers.attachSchema(new SimpleSchema({ 
    date: { 
     type: String, 
     label: "Date", 
     autoform: { 
      afFieldInput: { 
       class: "datepicker" 
      } 
     } 
    }, 
    departureTime: { 
     type: String, 
     label: "Departure Time", 
     autoform: { 
      afFieldInput: { 
       class: "timepicker" 
      } 
     } 
    }, 
    returnTime: { 
     type: String, 
     label: "Return Time", 
     autoform: { 
      afFieldInput: { 
       class: "timepicker" 
      } 
     } 
    }, 
    seats: { 
     type: Number, 
     label: "Seats" 
    }, 
    startLocation: { 
     type: String, 
     label: "Start Location" 
    } 
})); 

請注意:上面給出的示例使用領域date String類型。我強烈建議將date值存儲爲JavaScript Date對象。您可能想要使用beforehook將字符串轉換爲日期對象。