Opened 9 years ago

Closed 9 years ago

#12423 closed defect (fixed)

dojo.parser.instantiate does not read the new HTML5 custom data attributes

Reported by: Cormac Flynn Owned by: bill
Priority: high Milestone: 1.7
Component: Parser Version: 1.6.0
Keywords: dojo parser Cc:
Blocked By: Blocking:

Description

The method dojo.parser.instantiate accepts an array of nodes or objects and turns them into Dijit class instances.

Say I wished to instantiate as dijit.form.Form all DOM nodes with class '.form'. In versions previous to Dojo 1.6 I might create multiple nodes like this

<div dojoType="dijit.form.Form" class="form"/>

and then call

dojo.parser.instantiate(dojo.query('.form'));

The Dojo 1.6 docs state that in 1.6, data-dojo-type behaves exactly as dojoType, but this is not the case for instantiate. With the new node

<div data-dojo-type="dijit.form.Form" class="form"/>

the same call to dojo.parser.instantiate fails with the error "Could not load class 'null".

If you look at parser.js, method instantiate, the if/else block beginning at line 190, you'll see that the code still expects a dojoType attribute to be present on the node.

Change History (5)

comment:1 Changed 9 years ago by bill

Milestone: tbd1.7

The intended behavior was that once you start using data-dojo-type you need to use the new API to instantiate(). Though I can see why you want to be able to pass an array of nodes to instantiate(). I'll look into supporting that, see if I can support it as part of #12365.

About the doc, what's the URL of the doc you were looking at?

comment:2 Changed 9 years ago by Cormac Flynn

I was looking at the release notes

http://docs.dojocampus.org/releasenotes/1.6

"The dojoType attribute has been deprecated, and will be unsupported in 2.0. Replace all occurrences of dojoType with data-dojo-type, as the behavior is mostly identical, with the following caveats:" (the caveats being that you must also define a data-dojo-props attribute & retaining native attributes)

How do you mean "the new API to instantiate"?

comment:3 Changed 9 years ago by Cormac Flynn

(Since, as far as I can see, the API for dojo.parser.instantiate remains the same)

comment:4 Changed 9 years ago by bill

Oh, dojo.parser.instantiate() can take an array of objects, here's the API doc from the source code:

{
	type: "dijit.form.Button",
	node: DOMNode,
	scripts: [ ... ],	// array of <script type="dojo/..."> children of node
	inherited: { ... }	// settings inherited from ancestors like dir, theme, etc.
}

It's new to 1.6 so you can't see it on the API website yet. (Hopefully it will appear soon.)

comment:5 Changed 9 years ago by bill

Resolution: fixed
Status: newclosed

(In [24185]) Refactor parser to allow attributes (for a single node) to be partly specified in data-dojo-props, and partly specified directly ex: value=123. Uses node.attributes to detect which attributes are specified on a node, or for older versions of IE calls cloneNode(false) followed by some regex's on clone.outerHTML.

Due to lowercase/uppercase issues (ex: tabIndex, onClick), and for type conversion, the code still introspects each widget to get it's attribute metadata. In the future, would like to defer/avoid that in the common case. Fixes #10153, #12423, #12476, #10150, #9823, refs #11490 !strict.

Also fixes the problem on IE8 where a button without type=... defaults to type=submit rather than whatever the widget defines the default as, fixes #10163, refs #9334, #8946.

Future updates will be attached to ticket #12476.

Note: See TracTickets for help on using tickets.