Login Register

Create dialog and textbox(inside the dialog) programmatically

I need to create a dialog programmatically, here's the code:

var div = dojo.doc.createElement('div');
dojo.byId("canvas").appendChild(div);
var filedialog = new dijit.Dialog({ title: "Import an image file"}, div);
filedialog.show();
var textbox=new dijit.form.TextBox({type:"file"}, filedialog);
textbox.startup();

The dialog showed up, but I got this error message:
[Exception... "'Error: Tried to register widget with id==dijit_Dialog_0 but that id is already registered' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "" data: no]

If I changed the above the code to:
var div = dojo.doc.createElement('div');
dojo.byId("canvas").appendChild(div);
var filedialog = new dijit.Dialog({ title: "Import an image file"}, div);
filedialog.show();

var inp = div.appendChild(dojo.doc.createElement('input'));
var textbox=new dijit.form.TextBox({type:"file"}, inp);
textbox.startup();

or:
var textbox=new dijit.form.TextBox({type:"file"}, div);
textbox.startup();

The dialog showed up, but textbox not showing up in the dialog.

What's wrong with my code? Thanks!

-Sharon

The following general idiom

The following general idiom has worked for me with dialogs:

dialog.startup();
dialog.setContent(div);
dialog.show();

Where you prebuild the div with whatever you need, including the buttons.

-Adam

http://www.littleshoot.org
P2P Meets Web 2.0