Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#16030 closed defect (invalid)

Templated form does not replace inner widgets despite mixing in WidgetsInTemplate : dijit/_TemplatedMixin, dijit/_WidgetsInTemplateMixin, dijit/form/Form

Reported by: bishop Owned by:
Priority: undecided Milestone: tbd
Component: Documentation Version: 1.8.0
Keywords: Cc:
Blocked By: Blocking:

Description

Widgets inside a template are not replaced, despite mixing in dijit/_WidgetsInTemplateMixin.

Quick example, the input in the template will stay a vanilla <input>:

new TemplateForm({}, 'container');

// where TemplateForm is like:
        return declare([WidgetBase, TemplatedMixin, WidgetsInTemplateMixin, Form], {
            templateString:'<form data-dojo-attach-point="containerNode"><div><input data-dojo-type="dijit/form/TextBox" name="text" type="text" /></div></form>'
        });

What matters here is the order. If Form is put before the template mixins, all works as expected.

The docs* are clear that (a) the first class listed in super-classes is the base and the rest are mixins and (b) properties from the last-most class win.

What I didn't find clear in the docs is that when dealing with templated forms, the Form should be first then mixin the Template -- rather than the other way around.

See the attached files for an example. I think this is a documentation defect, but maybe it could be an enhancement (support any mixin order).

* http://dojotoolkit.org/documentation/tutorials/1.8/declare/

Attachments (1)

scenario.zip (1.5 KB) - added by bishop 7 years ago.

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by bishop

Attachment: scenario.zip added

comment:1 Changed 7 years ago by bishop

I'll add one point here, where I think the confusion lay. The template docs* say that to create a template widget, one super-classes like: [dijit._WidgetBase, dijit._TemplatedMixin].

What's not clear (to me, anyway, and this may only be my defect!) is that when you then want to do a templated form, you replace _WidgetBase with Form, like: [dijit.form.Form, dijit._TemplatedMixin]

I suppose what would clarify the docs is (1) that classes with "Mixin" in their name should come last, (2) mixin order shouldn't matter, and (3) templated forms are probably common enough to deserve their own distinct example.

* http://dojotoolkit.org/reference-guide/1.8/dijit/_TemplatedMixin.html

comment:2 Changed 7 years ago by ben hockey

Resolution: invalid
Status: newclosed

dijit/form/Form already uses WidgetBase? and TemplatedMixin?. all you should need to do is:

return declare([Form, WidgetsInTemplateMixin], {
  templateString: ...
});

this can be understood by reading the code or looking at the API docs http://dojotoolkit.org/api/1.8/dijit/form/Form.

the order of the mixins to declare produce an inheritance chain that is in a very specific ordered as determined by the C3MRO algorithm (http://dojotoolkit.org/reference-guide/1.8/dojo/_base/declare.html#multiple-inheritance). with this in mind, the order you provide the mixins matters so we won't be supporting any mixin order.

the reference guide is a wiki so we welcome updates if you think you can improve them.

comment:3 Changed 7 years ago by ben hockey

fyi - link to wiki is http://livedocs.dojotoolkit.org/dijit/_TemplatedMixin and you can use the same login you have here

Note: See TracTickets for help on using tickets.