gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:49:16 25 4
gpt4 key购买 nike

我正在使用 Meteor 和 Aldeed 的 Autoform。我想在提交之前检查用户是否确定。我已经尝试了很多方法,但是当我按下按钮时,表单仍然会提交。这是我现在所拥有的,它可以很好地生成一个模式(使用 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"); });
},

如何让表单等待用户确认或取消操作?

谢谢!

最佳答案

beginSubmit 在表单提交开始时调用。作为documentation状态,它可用于禁用/启用按钮或在提交较长请求时显示等待消息。如果您想根据用户的决定显示确认消息并提交表单,则需要使用 before Hook 。

例如:

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

关于javascript - 如何等待用户对 Meteor AutoForm 提交的响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36316623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com