2015-09-26 74 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 
     }