简体   繁体   English

如何等待用户对Meteor AutoForm提交的响应?

[英]How to wait for user response on Meteor AutoForm submission?

I am using Meteor and Aldeed's Autoform. 我正在使用Meteor和Aldeed的Autoform。 I want to check that the user is certain before submission takes place. 我想在提交之前检查用户是否确定。 I have tried many things but when I press the button, the form submits anyway. 我尝试了很多事情,但是当我按下按钮时,表单仍然会提交。 Here's what I have now, which produces a modal nicely (with SweetAlert) even though submission occurs in the background anyway: 这就是我现在所拥有的,即使提交始终在后台发生,它也可以很好地生成一个模态(使用SweetAlert):

AutoForm.hooks({
    createEventForm: {
        before: function() {
            this.event.preventDefault();
        },
        beginSubmit: function() {
            this.event.preventDefault();
            swal({
                title: "Are you sure?",
                text: "You will not be able to recover this imaginary file!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Yes, delete it!",
                closeOnConfirm: true },
                function(){
                swal("Deleted!", "Your imaginary file has been deleted.", "success"); });
        },

How can I make the form wait for the user to confirm or cancel the operation? 如何使表格等待用户确认或取消操作?

Thanks! 谢谢!

The beginSubmit is called at the beginning of the form submission. 在表单提交的开始处调用beginSubmit As the documentation states, it can be used to disable/enable buttons or showing a wait message when submitting longer requests. 文档所述,它可以用于禁用/启用按钮或在提交更长的请求时显示等待消息。 If you want to display a confirmation message and submit the form depending on the user's decision, you need to use the before hook. 如果要显示确认消息并根据用户的决定提交表单,则需要使用before挂钩。

For example: 例如:

AutoForm.hooks({
  createEventForm: hooksObject
});

var hooksObject = {
  before: {
    insert: function(doc) {
      var self = this;
      swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete it!",
        closeOnConfirm: true
      }, function(isConfirm) {
        if (isConfirm) {
          /* Submit form: */
          self.result(doc);
          swal("Deleted!", "Your imaginary file has been deleted.", "success");
        } else {
          /* Async cancel form submission: */
          self.result(false);
        }
      });
    }
  }
}

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

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