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}}

我希望能够使用日期、离开时间和返回时间输入(它们是pickadate.js的实现。但是,当我将表单提交到服务器时,这些输入不会作为表单的一部分被拾取。我如何要求输入在它们中以及将它们与自动表单一起提交?

4

1 回答 1

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"
    }
}));

请注意:上面给出的示例使用 String 类型作为 field date。我强烈建议将date值存储为JavaScript Date对象。您可能希望使用before 挂钩将字符串转换为日期对象。

于 2015-11-06T19:29:18.977 回答