Home > Ajax > dcomments.blogs.d.dojo_toolkit_blogs [ Add to favorite]
|
|
|
|
Blog > newsgroup > comments > blog
|
|
![]() |
Dojo 1.2 will sport a nice API standardization for widgets. Widget.attr() is now the standard interface for setting/getting all widget attributes. For example:
myTitlePane.attr('title', 'hello world'); // set title
var dis = myButton.attr('disabled'); // find out if button is disabled
myDateTextBox.attr('value', new Date()); // set to the current date
It also supports a hash API like dojo.attr(), for setting multiple attributes:
myInput.attr({ tabIndex: 3, disabled: true, value: 'hi'});
Notes for widget developers: The first thing to think about as a widget developer is that all the
documentation for an attribute needs to go next // value: Date
// The date picked on the date picker, as a Date Object. // When setting the date on initialization (ex: new DateTextBox({value: "2008-1-1"}) // or changing it (ex: attr('value', "2008-1-1")), you can specify either a Date object or // a string in ISO format The second thing is that when writing or extending a widget now you need to think of a "holy trinity" for each widget attribute:
Some attributes can only be specified at initialization time, but for
most of them, they can be changed after initialization, and users can
always get the <button>$</button>
That's compact and new myButtonWidget({label: 'hi'}) works fine, but myButtonWidget.attr('label', 'bye') doesn't. So, instead, you should be supporting this through the enhanced
attributeMap in the 1.2 release. So your attributeMap should map from the widget attribute to the DOM
node innerHTML. You can attributeMap: dojo.mixin(dojo.clone(dijit.layout.ContentPane.prototype.attributeMap), {
title: {node: "titleNode", type: "innerHTML" } }), (the fancy mixin stuff is so TitlePane's attributeMap has everything
that ContentPane has, It also supports class attributes like iconClass, see Menu for an
example of both in action: attributeMap: dojo.mixin(dojo.clone(dijit._Widget.prototype.attributeMap), {
label: {node: "containerNode", type: "innerHTML"}, iconClass: {node: "iconNode", type: "class" } }), Custom setters/getters When you have an attribute where setting/getting it is more complicated
than attributeMap can Custom setters are quite common. Usually you don't need a custom
getter (as the default action postCreate() Note that the application happens after buildRendering() but before
postCreate(), so Anyway, all this code is available in trunk now so I encourage you to
take it for a test drive. Bill |
Wed, 20 Aug 2008 |
||||
|
||||||
|
|
||||||