Error: Tried to register widget with id==grid1but that id is already registered

devMan picture devMan · Feb 8, 2010 · Viewed 13.9k times · Source

I am currently developing my personal website
and part of my site I have a biased view pr avoid duplication of code ...
and this view I have a dojox.grid.datagrid ...
I can call this view twice in the same page (ruban.phtml) the problem is that I click on 1 button that is the appeal of this view (partial view) and then I click the 2nd button that is the appeal of this view I have an error:
Error: Tried to register widget with id == grid but that id is already registered

and to address this problem, I removed the jsId walk the grid and I declared a global variable is initialized when calling the view:

grid = dijit.getEnclosingWidget(dojo.byId("gridId1");
// soit
grid = dijit.getEnclosingWidget(dojo.byId("gridId2");

I tried but I always with the same problem:

...... onDownloadEnd:function() {

          // Update the id of the grid
            var nodeGrid = dojo.byId("ancienIdGrid");
            nodeGrid.setAttribute("id", "newIdGrid");         
            varGlobalPourId = dijit.getEnclosingWidget(nodeGrid);

}....

Answer

peller picture peller · Feb 9, 2010

Dijit maintains a hash of id strings to widgets in dijit.registry (see dijit/_base/manager.js) Updating the id in the DOM will not affect that table, so I could see how it would fail if you try to create a widget with the same ID twice. How about just generating a unique id for each grid, if you need an id at all?