[英]Using Autoform package with Meteor Blaze but form won't submit. No errors
I am using autoForm to generate a form.我正在使用 autoForm 生成表单。 I have a schema set up using the simpl-schema package.
我有一个使用简单模式 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.我对 autoForm 将提交路由到哪个方法感到困惑。 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配方.html
<template name="insertRecipeForm">
{{> quickForm collection="Recipes" id="insertRecipeForm" type="insert"}}
</template>
recipe.js食谱.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.我的 recipe.js 文件中有一个旧的“recipes.insert”方法。 Does this interfere with autoForm?
这会干扰 autoForm 吗?
The insert
type only inserts on the client side. insert
类型仅在客户端插入。 If you want to pass the values to the meteor method you need to set type="method" meteormethod="recipes.insert"
如果要将值传递给 meteor 方法,则需要设置
type="method" meteormethod="recipes.insert"
Alternatively you can user type="normal"
and intercept the submit
event to use your custom submission:或者,您可以用户
type="normal"
并拦截submit
事件以使用您的自定义提交:
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见: https://github.com/Meteor-Community-Packages/meteor-autoform#non-collection-forms
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.