简体   繁体   English

流星AutoForm停止继续提交

[英]Meteor AutoForm stops proceeding submit

I would like to create a form, using the autoform package for Meteor, for my CAS_Entry collection. 我想使用流星的自动表单包为我的CAS_Entry集合创建一个表单。 The code can be seen below. 该代码可以在下面看到。 I also added the defined hooks, of which unfortunately only beginSubmit and before are executed and no entry is added to the collection. 我还添加了已定义的钩子,不幸的是,其中的钩子仅执行beginSubmitbefore ,并且没有条目添加到集合中。 Using Meteor shell, the insert works like a charm. 使用Meteor外壳,插入物就像一个饰物。

I am grateful for any hint. 我很感谢任何提示。

addCasEntry.html, Template for displaying the form: addCasEntry.html,用于显示表单的模板:

{{#autoForm collection="CAS_Entry" type="insert" id="addCasEntryForm"}}
  {{> afQuickField name="type" options="allowed"}}
  {{> afQuickField name="description" rows="6" type="textarea"}}
  {{> afQuickField name="file" type="cfs-file" collection="Images"}}
  {{> afQuickField name="date" }}
  <button type="submit" class="btn btn-primary">Add</button>
{{/autoForm}}

addCasEntry.js, adding debugging hooks: addCasEntry.js,添加调试钩子:

AutoForm.hooks({
  addCasEntryForm: {
    before: {
      insert: function(doc) {
        console.log(doc);
      }
    },
    after: {
      insert: function(error, result) {
        console.log('Occured error: ' + error);
      }
    },
    beginSubmit: function() {
      console.log('begin submit');  
    },
    onSuccess: function(formType, result) {
      console.log("Insert succeeded");
      console.log('Result ' + result);
    },
    onError: function(formType, error) {
      console.log('Error!!!');
      console.log(error);
    }
  }
});

SimpleSchema.debug = true;

/lib/collection/cas_entry.js: /lib/collection/cas_entry.js:

CAS_Entry = new Mongo.Collection("cas_entries");

CAS_Entry.attachSchema(new SimpleSchema({
  type: {
    type: String,
    allowedValues: ['reflection', 'evidence']
  },
  description: {
    type: String,
    optional: true
  },
  file: {
    type: String,
    optional: true,
  },
  timeUploaded: {
    type: Date,
    optional: true,
    autoValue: function() {
      return new Date();
    }
  },
  date: {
    type: Date,
  }
}));

CAS_Entry.allow({
  'insert': function() {
    return true;
  },
  'update': function() {
    return true;
  }
});

And here is the console output: 这是控制台输出:

控制台输出

Your form won't be submitted because you are not returning or passing the document to this.result(); 您的表单不会提交,因为您没有将文档返回或传递给this.result(); inside your before hook. 在您的before钩内。

AutoForm.hooks({
  addCasEntryForm: {
    // ...
    before: {
      insert: function(doc) {
        console.log(doc);
        return doc;
      }
    }
    // ...
  }
});

According to the documentation , you should use one of the following statements depending on your defined preconditions: 根据文档 ,应根据定义的先决条件使用以下语句之一:

  • Synchronous, submit: return doc; 同步,提交: return doc; .
  • Synchronous, cancel: return false; 同步,取消: return false; .
  • Asynchronous, submit: this.result(doc); 异步提交: this.result(doc); .
  • Asynchronous, cancel: this.result(false); 异步,取消: this.result(false); .

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

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