如何等待用户对 Meteor AutoForm 提交的响应?
How to wait for user response on Meteor AutoForm submission?
我正在使用 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 所述,它可用于 disable/enable 按钮或在提交较长请求时显示等待消息。如果要根据用户的决定显示确认消息并提交表单,则需要使用 before
挂钩。
例如:
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);
}
});
}
}
}
我正在使用 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 所述,它可用于 disable/enable 按钮或在提交较长请求时显示等待消息。如果要根据用户的决定显示确认消息并提交表单,则需要使用 before
挂钩。
例如:
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);
}
});
}
}
}