2015-09-26 45 views
0

我想使用quickform提交到服务器方法,我不认为它的工作。当我按提交时,我放入方法中的console.log似乎不会被调用。流星Autoform:methodserver不叫

下面是我的问题的演示。 https://github.com/afifsohaili/quickform-demo

Server.js:

Volunteer = new Mongo.Collection("volunteer"); 

if (typeof Schema === "undefined") Schema = {}; 
Schema.volunteer = new SimpleSchema({ 
    name: { 
    label: "Name", 
    max: 255, 
    type: String 
    }, 
    birthdate: { 
    label: "Birthday/DD-MM-YYYY", 
    type: String 
    }, 
    mobile_number: { 
    label: "Phone number", 
    type: String 
    }, 
    email: { 
    label: "Email address", 
    type: "email" 
    }, 
    facebook_url: { 
    label: "Facebook URL", 
    optional: true, 
    type: String 
    }, 
    university: { 
    label: "University", 
    optional: true, 
    type: String 
    }, 
    occupation: { 
    label: "Occupation", 
    optional: true, 
    type: String 
    }, 
    male: { 
    autoform: { 
     class: "with-gap", 
     falseLabel: "Female", 
     trueLabel: "Male", 
     type: "boolean-radios", 
    }, 
    label: " ", 
    type: Boolean 
    }, 
    transport: { 
    autoform: { 
     type: "boolean-checkbox" 
    }, 
    label: "I have my own transport", 
    type: Boolean 
    } 
}); 

Meteor.methods({ 
    registerVolunteer: function(doc) { 
    console.log(doc); 
    } 
}); 

HTML:

<head> 
    <title>test-quickform</title> 
</head> 

<body> 
    {{> hello}} 
</body> 

<template name="hello"> 
    <div class="row"> 
    <div class="col s12"> 
     {{> quickForm schema="Schema.volunteer" id="newVolunteerForm" 
      type="method" meteormethod="registerVolunteer" 
      buttonClasses="pink accent-3 waves-effect waves-light btn" 
      buttonContent="Continue" }} 
    </div> 
    </div> 
</template> 
+0

注意:.scss具有依赖关系,只是删除导入行并编译。 –

回答

1

createdAt type: "hidden"仍然验证客户端和预防方法调用由于没有价值。尝试添加optional: true并在服务器上设置该值。

顺便说一句,createdAt属性是缺少你的问题。

+0

这是真的。你会介意分享你如何调试吗? –

+0

打开浏览器控制台,输入'AutoForm.debug();'在点击提交按钮之前。它会向你显示调试信息,如'NewVolunteerForm预提交验证错误错误:创建于必须(...) –

0

你的表单验证失败,这防止调用 “registerVolunteer”。检查你的架构

// Run "before.method" hooks                      // 14 
    this.runBeforeHooks(this.insertDoc, function (doc) {                // 15 
     // Validate. If both schema and collection were provided, then we validate          // 16 
     // against the collection schema here. Otherwise we validate against whichever         // 17 
     // one was passed.                        // 18 
     var valid = (c.formAttributes.validation === 'none') ||               // 19 
      c.formTypeDefinition.validateForm.call({                  // 20 
      form: c.formAttributes,                     // 21 
      formDoc: doc,                        // 22 
      useCollectionSchema: c.ssIsOverride                  // 23 
      });                           // 24 
                                 // 25 
     if (valid === false) {                       // 26 
     c.failedValidation(); // <- Your code stops here                       // 27 
     }