[Dojo-interest] set data-dojo-type and data-dojo-props programmatically

249 views
Skip to first unread message

xing93111

unread,
Feb 2, 2012, 12:50:21 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
Hi there,

Is there a way to set data-dojo-type and data-dojo-props programmatically?

For example,
HTML:
<div id='example'>Hello world</div>
Javascript:
domAttr.set(dom.byId('example'), 'data-dojo-type', 'dijit.InlineEditBox');
domAttr.set(dom.byId('example'), 'data-dojo-props',
"editor:'dijit.form.TextBox'");

Thanks

-Bill

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/set-data-dojo-type-and-data-dojo-props-programmatically-tp3710647p3710647.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
________________________________________________________
Dojotoolkit: http://dojotoolkit.org
Reference Guide: http://dojotoolkit.org/reference-guide
API Documentation: http://dojotoolkit.org/api
Tutorials: http://dojotoolkit.org/documentation

Dojo-i...@mail.dojotoolkit.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Karl Tiedt

unread,
Feb 2, 2012, 1:01:51 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
just use the naitve methods of accessing data properties...
http://bit.ly/wTpt6a

-Karl Tiedt

xing93111

unread,
Feb 2, 2012, 1:07:36 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
Just tried:

var mydiv = document.getElementById('ie');
mydiv.setAttribute("data-dojo-type", "dijit.InlineEditBox");
mydiv.setAttribute("data-dojo-props", "editor:'dijit.form.TextBox'");

but it does not work.

Thanks

-Bill

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/set-data-dojo-type-and-data-dojo-props-programmatically-tp3710647p3710700.html


Sent from the Dojo Toolkit mailing list archive at Nabble.com.

Kitson Kelly

unread,
Feb 2, 2012, 1:14:29 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
When you say it doesn't work, what do you mean?  That the attributes don't get assigned to the DOM node or that something else you expected to happen didn't?

It is an odd thing to do what you are doing so why are you trying to do this and what is your expected outcome?

xing93111

unread,
Feb 2, 2012, 1:17:44 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
What I expect is after assignment, the div is clickable. So I can edit it.

Thanks

-Bill

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/set-data-dojo-type-and-data-dojo-props-programmatically-tp3710647p3710730.html

Karl Tiedt

unread,
Feb 2, 2012, 1:19:08 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
Yeah there is a lot more to widgets than just setting a data prop...

1) are you requiring the proper widget files?
2) are you manually running the parser, relying on parseOnLoad:true or
some other magic?

-Karl Tiedt

Kitson Kelly

unread,
Feb 2, 2012, 1:22:30 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
Also, if you are "going through the hassle" of setting the attributes, why do you just not create the Widget programatically, passing the node.id to the constructor and the Widget will take care of itself?

xing93111

unread,
Feb 2, 2012, 1:24:12 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
1. 'dijit/InlineEditbox' and 'dijit/form/TextBox' are required
2. in dojoConfig, I set parseOnLoad: true.

Anything more I need to pay attention to.

-Bill

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/set-data-dojo-type-and-data-dojo-props-programmatically-tp3710647p3710756.html


Sent from the Dojo Toolkit mailing list archive at Nabble.com.

Kitson Kelly

unread,
Feb 2, 2012, 1:28:34 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
Yes, when "parseOnLoad: true" then the parser has already completed when you get around to adding the attributes to the nodes.

If you really want to do what you are doing, you will have to turn parseOnLoad to false, require in the dojo/parser and then invoke the parser via parser.parse() after you have added the attributes.

xing93111

unread,
Feb 2, 2012, 1:35:41 PM2/2/12
to dojo-i...@mail.dojotoolkit.org
Great! It does what I want.

Thank you so much, Karl and Kitson!

-Bill

--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/set-data-dojo-type-and-data-dojo-props-programmatically-tp3710647p3710795.html

Reply all
Reply to author
Forward
0 new messages