Using Autoform package with Meteor Blaze but form won't submit. No errors

118 Views Asked by At

I am using autoForm to generate a form. I have a schema set up using the simpl-schema package. When I click submit on my form nothing happens. I don't get an error message and there is no new entry to my database. The schema appears to be working because the character minimum constraints display on the form if something is entered wrong.

I am confused at which method autoForm routes the submit to. From what I understand it should automatically do it and I don't need to create an event listener to handle the submit.

My code is below

recipe.html

<template name="insertRecipeForm">
  {{> quickForm collection="Recipes" id="insertRecipeForm" type="insert"}} 
</template>

recipe.js

export const Recipes = new Mongo.Collection('recipes');
const Schemas = {};
Schemas.Recipe = new SimpleSchema({
  name: {
    type: String,
    min: 1},
  instructions: {
    type: String,
    min: 5,
    autoform: {
      afFieldInput: {
        type: "textarea",
        rows: 2,
        class: "foo"
      }
    }
  },
  owner: {
    type: String,
    min: 1,
    autoform: {
      type: "hidden"
    }
  },
  username: {
    type: String,
    min: 1,
    autoform: {
      type: "hidden"
    }
  }},
    { tracker: Tracker })

Recipes.attachSchema(Schemas.Recipe)

I have an old 'recipes.insert' method in my recipe.js file. Does this interfere with autoForm?

1

There are 1 best solutions below

0
Jankapunkt On

The insert type only inserts on the client side. If you want to pass the values to the meteor method you need to set type="method" meteormethod="recipes.insert"

Alternatively you can user type="normal" and intercept the submit event to use your custom submission:

Template.myTemplate.events({
  'submit #insertRecipeForm' (event) {
    event.preventDefault() // cancel submission
    const { insertDoc } = AutoForm.getFormValues('insertRecipeForm')

    Meteor.call('recipes.insert', insertDoc)
  }
})

see: https://github.com/Meteor-Community-Packages/meteor-autoform#non-collection-forms