tags:

views:

693

answers:

3

i have a module. I need it to be able to display a modal dialog.

Seems like I need to inject a div into the main DOM and then parse it. Is this the right approach. Are there samples (or even a util- seems like this would not be that uncommon)

+2  A: 

There are samples for almost everything in DojoCampus and in the tests directory:

var pane = dojo.byId('thirdDialog');    
thirdDlg = new dijit.Dialog({
  id: "dialog3",
  refocus:false,
  title: "Programatic Dialog Creation"
},pane);

Note that this particular widget doesn't need to be inserted to the DOM manually - it appends itself to the end of the page. Here the second parameter to the Dialog constructor - pane - is a reference to the node whose content should be displayed inside the Dialog.

UPDATE: Based on the new information you should try this:

dojo.require("dijit.Dialog");
dojo.addOnLoad(function() {
    secondDlg = new dijit.Dialog({
        title: "Programatic Dialog Creation",
        style: "width: 300px",
        content: "Insert text here"
    });
    secondDlg.show()
});

As shown here, you can pass Dialog content in the content attribute. (This sample is executable in FireBug on any page that includes Dojo.)

UPDATE: So, you want to have a form inside the Dialog? Nothing special here. Hey, you can even have a dijit form over there! Be sure to check out that DojoCampus article on Dialogs to learn how Dialog can communicate with a dijit form.

dojo.require("dijit.Dialog");
dojo.require("dijit.form.TextBox");
dojo.addOnLoad(function() {
    secondDlg = new dijit.Dialog({
        title: "Programatic Dialog Creation",
        style: "width: 300px",
        content: "<h2>Sample Form</h2>" +
            "name: <input dojoType='dijit.form.TextBox' type='text' name='name' id='name'>"
    });
    secondDlg.show()
});

(Again this sample is executable in FireBug on any page that includes Dojo.)

Maine
i dont understand, where is thirdDialog?
'thirdDialog' is the id of a div element on that test page. Simply view the page source, search for 'thirdDialog' and you'll find an element that is initially hidden.
Maine
A: 

aha - I wasnt clear - my bad

I want the module to popup a dialog without the page author doing anything. No tags in foo.htm.

Could you please still clarify? The page author always has to include Dojo, add some content to the dialog, and connect it to some user action. I don't see how "without the page author doing anything" could work.
Maine
the main page is written by a guy using dojo. Yes. So he loads dojo, does a whole bunch of stuff. He uses my module , somewhere in my module I need to display a dialog. The page author is not aware of the fact that I want to do this (say I want a styled alert - not the use case but its an example). So the page author has no divs with dojo tags for me (I cannot even tell him what they are because they vary from invokation to invokation)
Ok, now I see. Have a look at the updated sample in my answer.
Maine
A: 

and content should be what?

suppose I want a dialog like this:

pm100
oops - html got filtered outdiv dojotype=textboxdiv dojotype=textboxdiv dojotype=textboxdiv dojotype=button
pm100
updated my comment again to show a form inside a dialog widget
Maine
You should update your question (or add a comment to someone else's answer) when you post an update/response to an answer.
seth