【问题标题】:Adding a custom input field to an AutoForm in Meteor在 Meteor 中向 AutoForm 添加自定义输入字段
【发布时间】:2015-11-07 05:52:44
【问题描述】:
  {{#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}}

我希望能够使用 date、departmentTime 和 returnTime 输入(它们是 pickadate.js 的实现。但是,当我将表单提交到服务器时,这些输入不会作为表单的一部分被拾取。如何我需要输入它们并使用自动表单提交它们?

【问题讨论】:

    标签: javascript meteor meteor-autoform pickadate simple-schema


    【解决方案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。我强烈建议将 date 值存储为 JavaScript Date 对象。您可能希望使用 before hook 将字符串转换为日期对象。

    【讨论】:

      猜你喜欢
      • 2018-09-07
      • 2015-05-08
      • 1970-01-01
      • 2016-07-17
      • 2015-05-19
      • 2016-01-22
      • 2011-03-13
      • 1970-01-01
      • 2019-07-29
      相关资源
      最近更新 更多