admin管理员组

文章数量:1321248

How to create a confirm dialog box in dojo? I would like to have an ok cancel dialog to appear on button click with dojo dialog (no javascript confirm dialog). So far i can only display a dialog on click event. Heres my code:

<script type="text/javascript">
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");

var secondDlg;
dojo.ready(function(){
    // create the dialog:
    secondDlg = new dijit.Dialog({
       title: "Programmatic Dialog Creation",
       style: "width: 300px",
   draggable:false
    });
});
showDialogTwo = function(){
   // set the content of the dialog:
   secondDlg.set("content", "Hey, I wasn't there before, I was added at " + new Date() + "!");
   secondDlg.show();
}
</script>
</head>
<body class="claro" style="margin-right:10px;">
<button id="buttonTwo" data-dojo-type="dijit.form.Button" data-dojo-props="onClick:showDialogTwo" type="button">Show me!</button>
</body>

How can i make this ok cancel dialog box?

How to create a confirm dialog box in dojo? I would like to have an ok cancel dialog to appear on button click with dojo dialog (no javascript confirm dialog). So far i can only display a dialog on click event. Heres my code:

<script type="text/javascript">
dojo.require("dijit.form.Button");
dojo.require("dijit.Dialog");

var secondDlg;
dojo.ready(function(){
    // create the dialog:
    secondDlg = new dijit.Dialog({
       title: "Programmatic Dialog Creation",
       style: "width: 300px",
   draggable:false
    });
});
showDialogTwo = function(){
   // set the content of the dialog:
   secondDlg.set("content", "Hey, I wasn't there before, I was added at " + new Date() + "!");
   secondDlg.show();
}
</script>
</head>
<body class="claro" style="margin-right:10px;">
<button id="buttonTwo" data-dojo-type="dijit.form.Button" data-dojo-props="onClick:showDialogTwo" type="button">Show me!</button>
</body>

How can i make this ok cancel dialog box?

Share Improve this question asked Jul 2, 2012 at 3:34 rockstarrockstar 1,3281 gold badge21 silver badges37 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2
<script type="dojo/method" event="onClick">
                    var dialog = new dijit.Dialog({
                        title: "Delete Switch Type",
                        style: "width: 400px",
                        content : "Do you really want to delete ?????<br>"
                    });
                   //Creating div element inside dialog
                    var div = dojo.create('div', {}, dialog.containerNode);
                    dojo.style(dojo.byId(div), "float", "left");

                    var noBtn = new dijit.form.Button({
                                label: "Cancel",
                                onClick: function(){
                                    dialog.hide();
                                    dojo.destroy(dialog);
                                }
                             });

                    var yesBtn = new dijit.form.Button({
                                label: "Yes",
                                style : "width : 60px",
                                onClick : <your function here>,
                                dialog.hide();
                    dojo.destroy(dialog);
                                }
                             });
                                  //adding buttons to the div, created inside the dialog
                    dojo.create(yesBtn.domNode,{}, div);
                    dojo.create(noBtn.domNode,{}, div);
                    dialog.show();
                </script>

I'm using this code as inline dojo/method - on the click event of the button. you can modify anyway

The Confirm Dialog is supported since Dojo 1.10.

See the release notes and the documentation.

The solution above does not take into account the little cross at the top right of the dialog.

I had done, long ago, a little suite of dialogs, you might find some happiness here, especially ConfirmDialog.js I just uploaded them on github today so you can take a look at them : http://github./PEM-FR/Dojo-Components/tree/master/dojox/dialog

They should be usable "as-is" or with minor changes

本文标签: javascriptconfirm dialog in dojoStack Overflow