繁体   English   中英

流星AutoForm停止继续提交

[英]Meteor AutoForm stops proceeding submit

我想使用流星的自动表单包为我的CAS_Entry集合创建一个表单。 该代码可以在下面看到。 我还添加了已定义的钩子,不幸的是,其中的钩子仅执行beginSubmitbefore ,并且没有条目添加到集合中。 使用Meteor外壳,插入物就像一个饰物。

我很感谢任何提示。

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,添加调试钩子:

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:

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;
  }
});

这是控制台输出:

控制台输出

您的表单不会提交,因为您没有将文档返回或传递给this.result(); 在您的before钩内。

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

根据文档 ,应根据定义的先决条件使用以下语句之一:

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

暂无
暂无

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

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