[英]Adding a custom input field to an AutoForm in Meteor
{{#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}}
I want to be able to use the date, departureTime and returnTime inputs (which are implementations of pickadate.js . However when I submit the form to the server, those inputs are not picked up as part of the form. How can I require input in them as well as submit them with the autoform? 我希望能够使用date,departmentTime和returnTime输入(它们是pickadate.js的实现。但是,当我将表单提交到服务器时,这些输入没有作为表单的一部分被提取。我如何要求输入以及使用自动表单提交?
You could use afFieldInput
elements and set the class
attribute in your Schema. 您可以使用
afFieldInput
元素并在Schema中设置class
属性。
For example: 例如:
<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"
}
}));
Please note: The example given above uses the type String for the field date
. 请注意:上面给出的示例将String类型用于字段
date
。 I strongly recommend to store date
values as JavaScript Date objects. 我强烈建议将
date
值存储为JavaScript Date对象。 You may want to use a before
hook to convert Strings to Date objects. 您可能需要使用一个
before
钩子将Strings转换为Date对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.