繁体   English   中英

流星自动格式:未调用methodserver

[英]Meteor Autoform: methodserver not called

我正在尝试使用quickform提交到服务器方法,但我认为它不起作用。 当我按下Submit时,似乎未调用我放入该方法中的console.log。

这是我的问题的演示。 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>

createdAt type: "hidden"仍在客户端上验证,并且由于没有值而阻止方法调用。 尝试添加optional: true并在服务器上设置值。

顺便说一句,您的问题上缺少createdAt属性。

您的表单验证失败,这阻止了调用“ 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
      }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM