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

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?

Matthias A. Eckhart
  • 5,136
  • 4
  • 27
  • 34
Austin Gayler
  • 4,038
  • 8
  • 37
  • 60

1 Answers1

1

You could use afFieldInput elements and set the class attribute in your Schema.

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. I strongly recommend to store date values as JavaScript Date objects. You may want to use a before hook to convert Strings to Date objects.

Matthias A. Eckhart
  • 5,136
  • 4
  • 27
  • 34