如何在进入下一步之前等待bootstrapdialog确认弹出窗口返回值? [英] How to wait for a bootstrapdialog confirmation popup to return a value before going to next step?

查看:507
本文介绍了如何在进入下一步之前等待bootstrapdialog确认弹出窗口返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个通用对话框弹出功能,在执行保存或删除功能之前会要求用户进行确认。但是点击保存按钮页面不等待弹出回复。这是我的代码。



我尝试过:



我的函数(返回true或false): -

I have created a universal dialog popup function which will asked the users for confirmation before executing save or delete functionality.But the on clicking the save button the page it not wait for the popups reply.Here is my code.

What I have tried:

My function (returns true or false ):-

function DiaglogNormal(_title, _message) {
    debugger;
    
    BootstrapDialog.confirm({
        title: _title,
        message: _message,
        type: BootstrapDialog.TYPE_PRIMARY,
        closable: true, 
        draggable: true,
        btnCancelLabel: 'Cancel', 
        btnOKLabel: 'Yes',
        btnOKClass: 'btn btn-success',
        btnCancelClass: 'btn btn-warning',
        callback: function (result) {
            // result will be true if button was click, while it will be false if users close the dialog directly.
            if (result) {
                //alert('Yup.');
                return true;
            } else {
                //alert('Nope.');
                return false;
            }
        }
    })
    }





控制它的调用位置:





Control where it is called :

<input type="submit" name="button" formnovalidate value="@WFCommon.BTN_Save"  id="btnSave" class="btn btn-primary" />





点击按钮时的功能:





Function when the button is clicked:

$("#btnSave").click(function () {
            debugger;           
            
            if (DiaglogNormal('Confirmation', 'Continue To Save ??...'))
                {
                    RemoveInputReviewerRules("#WorkflowDraft", 'input[alt="txtApprovers[]"]');
                }
                else
                {
                    return false;
                }
            
        });





请帮助我们了解如何使点击事件功能等待调用函数结果。



Please help on how to make the click event function to wait for the calling function result.

推荐答案

#btnSave)。点击( function (){
debugger ;

if (DiaglogNormal(' 确认'' 继续保存?? ...'))
{
RemoveInputReviewerRules( #WorkflowDraft' 输入[alt =txtApprovers []]');
}
else
{
return false < /跨度>;
}

});
("#btnSave").click(function () { debugger; if (DiaglogNormal('Confirmation', 'Continue To Save ??...')) { RemoveInputReviewerRules("#WorkflowDraft", 'input[alt="txtApprovers[]"]'); } else { return false; } });





请帮助我们了解如何使点击事件功能等待调用函数结果。



Please help on how to make the click event function to wait for the calling function result.


不幸的是,BootstrapDialog.confirm()是异步的,因此它不会等待。您单击提交按钮后,表单将继续提交。要解决此问题,您必须首先通过添加以下内容来阻止提交按钮的此默认行为:
Unfortunately, BootstrapDialog.confirm() is asynchronous, so it does not wait. You form will go ahead with the submission upon clicking of the submit button. To get around this, you have to first prevent this default behavior of the submit button from happening by adding:


(#btnSave)。单击(功能( e){
e.preventDefault();
//省略
("#btnSave").click(function(e){ e.preventDefault(); // omitted

这将阻止表单提交并允许显示确认对话框。

接下来,当回调函数返回为true时,您将添加代码以提交表单,执行以下操作:

This will stop the form from submitting and allow the confirm dialog to show.
Next, you will add code to submit the form when the return from callback is true, do this:

callback: function(result) {
    if(result) {
	// whatever code you want to run 
	// to submit the form


这篇关于如何在进入下一步之前等待bootstrapdialog确认弹出窗口返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆