Login Register

Destroy Dialog (or other dijit) programmatically

[Editor: moving to the appropriate forum...]

hi all,
I'm having problem for destroying Dialog programmatically.
I explain : i have a page (included in another one by dojox.layout.ContentPane but no matter here) with several dijit.form.Dialog and i can't refresh it because of : "Couldn't create widget in include from pages/new_profile.php. Error : tried to register widget with id == myDialog but that id is aleady registered".
Clearly, i have to destroy the widget before refreshing the page (i call them declaratively in my page).

To destroy all the Dialog in my page, i found one solution :
<code>
function init() {

dojo.query("dijitDialog", document).forEach(function(tag) {//i can easily reference the dijit with dojo.query

killDialog(tag);// function which destroy the "tag" passed by the dojo.query
});

}
function killDialog(tag) {

dijit.byId(tag.id).destroyRecursive();

}
</code>

With that solution, one problem i don't understand : i get the message "dijit.byId(tag.id) has no properties".

Is anyone got a solution???
I've tried for 1 week to solve this problem.

Thank you for your (future) help!
Squinty

The original provider of the

The original provider of the code probably meant:

dojo.query(".dijitDialog", document)....   //note the "." in .dijitDialog, indicating "class"

It"s not that

No sorry it was just a mistake when i wrote the post.. But i watch the the response of "dojo.query" with a console.log and querying all the Dailog in the page is not a problem.
The problem is really ; "dijit.byId(tag.id) is not a function"

Thks anymore

For what it's worth, with

For what it's worth, with the change noted above, it works fine on the test_Dialog.html page. The only reason I could see it wouldn't work, other than a typo, is if one of the dialogs did not have an "id".

In looking again...the first time you reported the error, it was: ""dijit.byId(tag.id) has no properties".

In a later post, your error message was: "dijit.byId(tag.id) is not a function", the only function there is dijit.byId, and, of course, dijit.byId is a function, if dojo is properly loaded. I sometimes mistype and put dijit.byID, which is not a function.

I suggest you try the individual steps in the two functions in your post inside Firefox's Firebug console. You will quickly find where it fails. Good luck!

try

try dijit.getEnclosingWidget(tag).destroyRecursive(); ?

or dijit.byNode(tag) if the domNode being returned from the query. there is a dijit.registry of all widgets in a page, you could iterate through that, too, inspecting values.

Thks (but lots of post mistake from me)

Thks for your comments, i will try all of your solutions as soon as possible.
>> frankf : i'm sorry for my previous post but the error message was really "...has no properties". It was just a mistake. I'm so tired this days, too much parties i think..
Thks!

Alléluia!!

dante you are a genius!!!
Your both solutions work!!
The final solution is :

dojo.query('.dijitDialog', document).forEach(function(tag) {

                                                              dijit.byNode(tag).destroyRecursive();// or dijit.getEnclosingWidget(tag).destroyRecursive();

                                                               });

Thank you very much man! "jte kiffe trop grave!"

Squinty