Opened 7 years ago

Closed 3 years ago

#14447 closed defect (patchwelcome)

mvc.Repeat ignores widgets created by first parser run

Reported by: Stefan Meyer Owned by: Ed Chatelain
Priority: high Milestone: 1.11
Component: DojoX MVC Version: 1.7.1
Keywords: Cc:
Blocked By: Blocking:

Description

When the parser parses the template and creates the widgets, it also creates widgets for children of a Repeat-Widget. These will be discarded and replaced by the Repeat-Widget. The orignally created widgets hang around though and can be retrieved by calling dijit.byId. This causes a duplicate id problem when you dispose the widget and create it again from the template and define dynamical ids like :

id="idInput#{this.index}

Change History (7)

comment:1 Changed 7 years ago by bill

Sounds like there are a number of problems, but you might want to start off by defining mvc.Repeat.stopParser = true, so that the parser doesn't parse the contents. inside the Repeat widget.

comment:2 Changed 7 years ago by Ed Chatelain

Can you provide a simple testcase to show the problem? Thanks.

comment:3 Changed 7 years ago by Stefan Meyer

Unfortunately stopParser does not work inside a _Templated widget because it is overridden by the template=true property of the parser.

comment:4 Changed 6 years ago by digiwise

I have encountered this problem too. You can see a test file (based on dojox/mvc/tests/test_templatedWidget/test_mvc_widget.html) at:

http://amertec.digiwise.com.au/client/src/dojox/mvc/tests/test_templatedWidget/test_mvc_widget_destroy.html

The patch to make the test case is:

*** dojox/mvc/tests/test_templatedWidget/test_mvc_widget.html   2012-12-18 09:54:17.000000000 +1100
--- dojox/mvc/tests/test_templatedWidget/test_mvc_widget_destroy.html   2012-12-18 12:35:28.000000000 +1100
***************
*** 15,20 ****
--- 15,21 ----
                                "dojox/mvc/getStateful",
                                "dojox/mvc/ModelRefController",
                                "dojox/mvc/tests/test_templatedWidget/myMvcTemplated",
+                               "dijit/form/Button",
                                "dojo/domReady!"
                        ], function(parser, getStateful, ModelRefController, myMvcTemplated){
                                ctrl = new ModelRefController({model: getStateful([
***************
*** 57,62 ****
--- 58,65 ----
                                        <div>
                                                Test exprchar. Widget template test uses exprchar of # and others for template:#{this.index} etc.
                                        </div>
+                                       <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ require('dijit/registry').byId('container2').destroyRecursive(false); }">Destroy Widget</button>
+                                       <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ alert(require('dijit/registry').byId('nameInput#{this.index}')); }">Check registry</button>
                                        <br/>
                                        <div id="container2" data-dojo-type="dojox.mvc.tests.test_templatedWidget.myMvcTemplated" data-dojo-props="ctrl: ctrl"></div>
                                </div>

The second button shows that registry.byId('nameInput#{this.index}') returns a widget before and after the templated widget is destroyed (destroy it with the first button). As stemey said this means if you try to destroy the widget then create it again you get an error like:

Error: Tried to register widget with id==nameInput#{this.index} but that id is already registered http://amertec.digiwise.com.au/client/src/dijit/registry.js
Line 28

comment:5 Changed 6 years ago by digiwise

Further to my message above, this applies to Dojo 1.8.1

comment:6 Changed 6 years ago by Ed Chatelain

Thanks for the testcase. I am on vacation until early January so I will not be able to work on this until I return.

comment:7 Changed 3 years ago by dylan

Milestone: tbd1.11
Resolution: patchwelcome
Status: newclosed

dojox/mvc is not actively maintained. If someone wants to work on pull requests for the issues, we'll consider them.

Note: See TracTickets for help on using tickets.