Jquery UI dialog in place of javascript confirm

后端 未结 3 1736
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 04:45

I have a bunch of validation javascript processes with confirms. I want to use jquery ui dialog, but I need to return true for the rest of the validation processes.

3条回答
  •  执念已碎
    2021-01-13 05:31

    In jQuery UI dialog, set the modal option to true, and specify primary and secondary user actions with the buttons option.

        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: [{
                text: pm_info_msg_013,
                click : function() {    
                    $( this ).dialog( "close" );
                    // code related to "where_to_coupon== true" goes here
                    // submit form
                    }
                }, {
                text: "Cancel",
                click: function() {
                    $( this ).dialog( "close" );
                    doSubmit = false;
                    // don't submit form
                }}]
        });
    

    See the demo here: http://jqueryui.com/demos/dialog/#modal-confirmation

    Update: This will allow you to create multiple confirms. Usage:

    function CreateDialog(okText, cancelText, okCallback, cancelCallback) {
            $( "#dialog-confirm" ).dialog({
                resizable: false,
                height:140,
                modal: true,
                buttons: [{
                    text: okText,
                    click : function() {    
                        $( this ).dialog( "close" );
                        okCallback();
                        }
                    }, {
                    text: cancelText,
                    click: function() {
                        $( this ).dialog( "close" );
                        cancelCallback();
                    }}]
                }
            });
    
    // ******* usage #1 ********    
    CreateDialog(pm_info_msg_013, "Cancel", function () {
       // where_to_coupon== true
    }, function() {
    
       // where_to_coupon== false
    });
    
    function OnConfirmTrue() {
      // do something
    }
    
    function OnConfirmFalse() {
      // do something
    }
    
    // ******* usage #2 ********
    
    CreateDialog(pm_info_msg_013, "Cancel", OnConfirmTrue, OnConfirmFalse);
    

提交回复
热议问题