rakesh menon
rakesh menon

Reputation: 1101

Action bar is not displaying in dijit dialog when using href attribute

I have the following code

var dlg = new dijit.Dialog({
        "title": "my dialog",
        "style": "width: 800px;",
        "id": "myDlg",
        "href":"some url"
    }).placeAt(dojo.body());


    var actionBar = dojo.create("div", {
        "class": "dijitDialogPaneActionBar"
    }, dlg.containerNode);

    new dijit.form.Button({
        "label": "Ok"
    }).placeAt(actionBar);
    new dijit.form.Button({
        "label": "Cancel"
    }).placeAt(actionBar);

    dlg.show();

with this code dialog is displaying with the url content but action bar is not showing,when i replace the href with some static content action bar is working fine.What could be the problem?

Upvotes: 0

Views: 707

Answers (1)

vivek_nk
vivek_nk

Reputation: 1600

When using "href" for the dojo Dialog, the content from the href loads as an ajax call every time the dialog is opened/showed. So, what happens here is your action bar and button are added first and then the href is loaded into the Dialog, which overwrites the existing action bar and the buttons -EVERYTIME!! So, to achieve this, you can ensure that the action bar is added, once the href load is completed. For this, we use the Deferred object returned by the "show" method.

var dlg = new dijit.Dialog({
    "title": "my dialog",
    "style": "width: 800px;",
    "id": "myDlg",
    "href":"some url"
}).placeAt(dojo.body());

dlg.show().then(function() {
  if(dlg.firstTime) {
     var actionBar = dojo.create("div", {
        "class": "dijitDialogPaneActionBar"
     }, dlg.containerNode);

     new dijit.form.Button({
       "label": "Ok"
     }).placeAt(actionBar);
     new dijit.form.Button({
       "label": "Cancel"
     }).placeAt(actionBar);
     dlg.firstTime=true;
   }
});

But, i would suggest not to use this approach, because, every time, you create the action Bar and button widgets. So, i have added a parameter "firstTime" to dialog object to avoid it. SO, action bar and buttons are crated only one time. Hope this helps.

Upvotes: 1

Related Questions