Dojo and unregistering widgets
Solution 1
If you're looking to unregister specific widgets, you can use their destroy()
or destroyRecursive()
methods. The second one destroys any widgets inside the one you are destroying (i.e. calling destroyRecursive on a form widget will also destroy all the form components).
In your case, it sounds like your best bet would be to do this before jQuery.load
-
var widgets = dijit.findWidgets(<containerDiv>);
dojo.forEach(widgets, function(w) {
w.destroyRecursive(true);
});
The above code will unregister all widgets in <containerDiv>
, and preserve their associated DOM Nodes. To destroy the DOM nodes, pass false
to destroyRecursive
instead.
Reference:
http://dojotoolkit.org/api/1.3/dijit/_Widget/destroyRecursive
Solution 2
Based on http://bugs.dojotoolkit.org/ticket/5438, I found a sufficient way of destroying dojo-widgets:
dijit.registry.forEach(function(w){
w.destroy();
});
Solution 3
This worked for me:
dijit.byId( 'myButton' ).destroy( true );
Solution 4
I think you would be better off removing the id from your button and accessing it using an attach point. You would basically do <button dojoType="dijit.form.Button" data-dojo-attach-point="myButton">button</button>
then in your code you would access it like this.myButton....
however im not sure which version of dojo you are using. This will fix any id issues since dojo will assign a unique id to it automatically.
Related videos on Youtube
John Korsnes
BY DAY: Alt-Rock Ninja Cowgirl at Veridian Dynamics. BY NIGHT: I write code and code rights for penalcoders.example.org, an awesome non-profit that will totally take your money at that link. My kids are cuter than yours. FOR FUN: C+ Jokes, Segway Roller Derby, NYT Sat. Crosswords (in Sharpie!), Ostrich Grooming. "If you see scary things, look for the helpers-you'll always see people helping."-Fred Rogers
Updated on August 09, 2020Comments
-
John Korsnes over 3 years
I am new to the Dojo Toolkit. I'm getting the error
Tried to register widget with id=myButton but that id is already registered
whenever I try to load dojo content twice (meaning I load HTML content through jQuery.Load into a container div). Is there a way of unregistering already registered widgets in dojo? I've seen some examples, but I don't really get them working.
My button:
<button dojoType="dijit.form.Button" id="myButton">button</button>
-
John Korsnes about 14 yearsOthers looking for a solution : See also answer below for non-recursive solution.
-
mtchuente about 8 yearsExactly what I was looking for. Thanks a bunch!