javascript - Dojo duplicate ID error when instantiating a widget programmatically, but not declaratively -
i'm using dojo 1.10.
i'm trying test custom widget, error duplicate id when add programmatically in html file. adding declaratively works ok. in past i've gotten error when accidentally used id attribute in widget template, don't have id in template. here's pared-down example:
demo/testwidget.js
define([ "dojo/_base/declare", "dijit/_widgetbase", "dijit/_templatedmixin", "dijit/_widgetsintemplatemixin", "dojo/text!./template/testwidget.html", "dijit/layout/contentpane", ], function(declare, _widgetbase, _templatedmixin, _widgetsintemplatemixin, template) { return declare([_widgetbase, _templatedmixin, _widgetsintemplatemixin], { baseclass: 'testwidget', templatestring: template, }); }); demo/testwidget.html
<div data-dojo-attach-point="containernode"> <div data-dojo-type="dijit/layout/contentpane"> random stuff </div> </div> index.html:
<head> <script> var baseloc = location.pathname.replace(/\/[^/]+$/, ""); var dojoconfig = { parseonload: true, async: true, packages: [ { name: "demo", location: baseloc + "/demo" } ] }; </script> <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script> <script> require([ "demo/testwidget.js", "dojo/domready!" ], function(testwidget) { var widget = new testwidget({ }, 'testnode'); }); </script> </head> <body class="claro"> <div id="testnode"></div> </body> for above code, i'm getting error "tried register widget id==dijit_layout_contentpane_0 id registered". if delete testwidget instantiation in script , replace 'testnode' with:
<div data-dojo-type="demo/testwidget"></div> it works ok. ideas i'm doing wrong?
i think problem parsing going on while new element being created, due parseonload being true. if can set false , call parse explicitly if needed, should able avoid it.
Comments
Post a Comment