将自定义输入字段添加到 Meteor 中的自动表单
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}}
我希望能够使用日期、出发时间和返回时间输入(这是 pickadate 的实现.js。但是,当我将表单提交到服务器时,这些输入不会作为表单的一部分进行拾取。我如何要求输入它们以及将它们与自动表单一起提交?
您可以使用
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
。我强烈建议将date
值存储为 JavaScript Date 对象。您可能希望使用 before
挂钩将字符串转换为 Date 对象。
相关文章:
- 如何将JS数组添加到Meteor自动表单条目中
- Meteor JS自动表单自定义输入-没有当前视图
- 如何使表单出现在Meteor中的点击事件中
- Meteor:具有两个提交按钮的表单(确定事件处理程序中单击的按钮)
- 使用 Meteor 框架从表单输入中提取数据时出现问题
- 如何在 Meteor 中添加与自动表单的关系或引用
- 在 Meteor.js 中保留表单值
- 在 Meteor 中,如何使表单加载从先前从 MongoDB 集合中提取的插入对象预填充
- 从 Html 表单 Meteor javascript 获取 Var 时出错
- 在Meteor TODO应用程序中向表单添加另一个字段
- 我应该为onchange表单提交什么Meteor事件处理程序
- 验证Meteor中的表单
- 将自定义输入字段添加到 Meteor 中的自动表单
- Meteor AutoForm:带id的表单;asdf”;需要“;模式“;或“;集合“;属性
- Meteor(0.9.0.1):使用Helper和自动表单为多个用户更新记录
- 如何在meteor.js中创建联系表单
- 如何在Meteor的相同集合字段中添加来自相同表单的两个输入
- Meteor:自动表单模板发布项目从0.9.3.1升级到1.2.0.2
- 在Meteor.js中填写向导表单后创建用户
- 如何在Meteor中为带有输入单元格表的表单做响应式绑定?