Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:20:15+00:00 2026-06-03T02:20:15+00:00

I would like to add a generic dialog with Ok and Cancel buttons support

  • 0

I would like to add a generic dialog with “Ok” and “Cancel” buttons support callback functions.

How can I achieve this with a Dojo AMD?

For example:

  myDialog = new Dialog ({

  title: "My Dialog",
  content: "Are you sure, you want to delete the selected Record?",
  style: "width: 300px",
  onExecute:function(){ //Callback function 
      console.log("Record Deleted") 
  },
  onCancel:function(){ 
      console.log("Event Cancelled") } 
  });
  // create a button to clear the cart
   new Button({ label:"Ok"
       onClick: myDialog.onExecute()
   }

   new Button({ label:"Cancel"
        onClick: function(){ myDialog.onCancel() }
   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:20:17+00:00Added an answer on June 3, 2026 at 2:20 am

    Here is the solution I came up when I had been facing the same question. It’s not completely programmatic, but using the template makes the code more readable and flexible for changes.

    Better to see once than to hear 100 times, so see all the code below live at jsFiddle: http://jsfiddle.net/phusick/wkydY/

    The main principle I employ is the fact that dijit.Dialog::content may not only be a string, but also a widget instance. So I subclass dijit.Dialog to declare ConfirmDialog class. In ConfirmDialog::constuctor() I declare and instantize a widget from a template and set it to be dialog’s content. Then I wire onClick actions in ConfirmDialog::postCreate() method:

    var ConfirmDialog = declare(Dialog, {
    
        title: "Confirm",
        message: "Are you sure?",
    
        constructor: function(/*Object*/ kwArgs) {
            lang.mixin(this, kwArgs);
    
            var message = this.message;
    
            var contentWidget = new (declare([_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], {
                templateString: template, //get template via dojo loader or so
                message: message    
            }));
            contentWidget.startup();
            this.content = contentWidget;
        },
    
        postCreate: function() {
            this.inherited(arguments);
            this.connect(this.content.cancelButton, "onClick", "onCancel");
        }
    
    })
    

    The template markup:

    <div style="width:300px;">
    
      <div class="dijitDialogPaneContentArea">
        <div data-dojo-attach-point="contentNode">
            ${message}              
        </div>
      </div>
    
      <div class="dijitDialogPaneActionBar">
    
        <button
          data-dojo-type="dijit.form.Button"
          data-dojo-attach-point="submitButton"
          type="submit"
        >
          OK
        </button>
    
        <button
          data-dojo-type="dijit.form.Button"
          data-dojo-attach-point="cancelButton"
        >
          Cancel
        </button>
    
      </div>
    
    </div>
    

    Now use ConfirmDialog instead of dijit.Dialog:

    var confirmDialog = new ConfirmDialog({ message: "Your message..."});
    confirmDialog.show();
    

    Important: Do not forget to disconnect any connects to the dialogs callbacks and destroy dialog when closed.

    If you use ConfirmDialog often and in multiple places of your code consider this:

    var MessageBox = {};
    MessageBox.confirm = function(kwArgs) {
        var confirmDialog = new ConfirmDialog(kwArgs);
        confirmDialog.startup();
    
        var deferred = new Deferred();
        var signal, signals = [];
    
        var destroyDialog = function() {
            array.forEach(signals, function(signal) {
                signal.remove();
            });
            delete signals;
            confirmDialog.destroyRecursive();
        }
    
        signal = aspect.after(confirmDialog, "onExecute", function() {
            destroyDialog();
            deferred.resolve('MessageBox.OK');
        });
        signals.push(signal);
    
        signal = aspect.after(confirmDialog, "onCancel", function() {
            destroyDialog();   
            deferred.reject('MessageBox.Cancel');            
        });
        signals.push(signal);
    
        confirmDialog.show();
        return deferred;
    }
    

    Your code will be more readable and you will not have to deal with cleaning up:

    MessageBox.confirm().then(function() {
        console.log("MessageBox.OK")
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to add an item into a picture Library using c#. This
I would like to add some custom elements to a mule flow, like this:
I have a generic layout in XML I would like to programmatically add after
This should hopefully be a simple one. I would like to add an extension
I would like to add some paragraphs or new lines or words dynamically but
I would like to add a field to the Django FlatPage database model, but
I would like restfully add a parameter to the new named path. So for
I would like to add some custom data to an image the user generates
I would like to add authentication to my Rails app. I came across few
I would like to add an overlay image on a Google Map. The image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.