Opened 12 years ago

Closed 10 years ago

Last modified 6 years ago

#4501 closed defect (wontfix)

Widgets cannot be root of templates

Reported by: guest Owned by:
Priority: high Milestone: future
Component: Dijit Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

HOW TO REPRODUCE:

Click on: http://82.230.65.68:31416/~fred/dojo/fred_samples/bug_004.html

RESULT:

A web page that displays a normal html button and a tundra button

EXPECTED RESULT:

Both buttons should be tundra styled

REASON:

The first button is constructed by a widget which have the following templateString:"<button dojoType="dijit.form.Button">Button 1</button>". The dojoType fragment is ignored because it is at the root of the hierarchy.

The bug is here reproduced with a button as the root of the template, which is an uncommon occurence, but it also prevents having Layout or ContentPane? as the top level of the template, which is IMO much more serious.

At minimum the "widgetsInTemplate:true" code should raise an error if the top-level element have a dojoType attribute.

Change History (6)

comment:1 Changed 12 years ago by Adam Peller

Component: GeneralDijit
Owner: anonymous deleted

comment:2 Changed 12 years ago by bill

Milestone: 2.0

comment:3 Changed 11 years ago by alex

Milestone: 2.01.3

Milestone 2.0 deleted

comment:4 Changed 10 years ago by bill

Description: modified (diff)
Milestone: 1.3future

comment:5 Changed 10 years ago by bill

Resolution: wontfix
Status: newclosed

Forgot this ticket was here; I wrote about this issue in http://bugs.dojotoolkit.org/ticket/9477#comment:4.

As I said in the linked comment, the problem is that in the generated DOM, the main widget's id and the templated widget's id will try to be applied to the same node. I can't think of a solution currently, although I do sympathize w/the problem you are saying about not being able to have a layout widget as the root of your template.

comment:6 Changed 6 years ago by bill

The way to get this to work (with the current code) is to mix in the classes you want into _TemplatedMixin. I.E. instead of trying:

declare("MyWidget", [_WidgetBase, _TemplatedMixin], {
   templatedString: "<div dojoType=dijit/Menu>...",
   ...
})

Do this:

declare("MyWidget", [_WidgetBase, _TemplatedMixin, Menu], {
   templatedString: "<div>...",
   ...
})

It's not officially supported, but will probably work.

To support this better in the future, we could conceivably give _Templated a factory method, like _Templated.compile() or _Templated.create(), that would take an optional superclass X (or multiple superclasses), and a template string, and return a new constructor XTemplated. To be used like:

_Templated.create(null, "<div data-dojo-type=dijit/Menu>...")

It could also define XTemplated.UnTemplatedClass (or some better name) to point to X, in case someone needed access to that original class at some point.

That would be a big change, albeit interesting.

Note: See TracTickets for help on using tickets.