簡體   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