Custom Widgets
This page contains information for people writing their own widgets. If you are just using the dijit widgets out of the box, you can skip this section.
Widget Declaration
dojo.defineWidget() has been replaced by plain dojo.declare()
Widget Creation
Widget creation method call sequence:
- postMixInProperties()
- fillInTemplate() is no longer called.
- buildRendering() - swaps out the source HTML with the widget's HTML, typically from a template. _Templated mixin defines this function.
- postCreate() is called. Note that unlike 0.4, the children don't yet exist
- startup() is called after all the other widgets have been created
Note that those functions' (postCreate, etc) call signatures have changed. No arguments are passed.
To get the source dom Node, just reference this.srcNodeRef
Base Classes
In 0.4 there were three main base classes (Widget, DomWidget, and HtmlWidget), but everyone used HtmlWidget so we can think of that as one class. 0.9 split up things by functionality, into:
- dijit._Widget
- dijit._Templated
- dijit._Container
- dijit._Contained
- dijit.layout._LayoutWidget
- dijit.form._FormWidget
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dijit._Container");
dojo.require("dijit.layout._LayoutWidget");
dojo.require("dijit.form._FormWidget");
Name changes
| 0.4 | 0.9 | Comments |
|---|---|---|
| children | deleted | Mixin dijit._Container and call getChildren() |
| parent | deleted | Mixin dijit._Contained and call getParent() |
| extraArgs | deleted | declare all parameters to your widget as attributes in the widget |
| disabled | disabled | in _FormWidget |
| widgetId | id | |
| widgetType | declaredClass | |
| ns | deleted | No namespaces anymore; use full path to widget like dijit.form.Button |
| templateString, templatePath | Mix in dijit._Templated | |
| templateCssPath | deleted | Include CSS rules directly |
| toggle, toggleDuration | deleted | Use dojo functions (fadeIn, wipeIn) on widget.domNode directly. Some widgets like Dialog still support these attributes (or similar ones) but it's not builtin to every widget. |
| isContainer | deleted | No longer necessary; all widgets can be containers. |
| 0.4 | 0.9 | Comments |
|---|---|---|
| enable, disable | setDisabled | |
| onResized | layout | when layout is called size is in this._contentBox |
| create | constructor calls lifecycle code | |
| fillInTemplate | deleted | use postCreate() instead |
| postInitialize | deleted | use postCreate() instead |
| postCreate | when postCreate() is called children don't yet exist. If you need to access them, use startup() | |
| destroy | destroyRecursive | destroy() doesn't destroy child widgets |
| getChildrenOfType | deleted | use dojo.filter(this.getChildren(), function(child){...}) |
| addChild, removeChild | mix in dijit._Container | |
| isShowing, toggleShowing | deleted | Reference this.domNode directly |
| show, onShow, hide, onHide | deleted | Some widgets support these functions but not all widgets. Reference this.domNode directly if necessary. |
| resizeTo(w, h) | resize({w: 10, h: 20}) | Now you can just change height or width (each argument is optional) |
| resizeSoon | deleted | shouldn't be necessary; layout algorithms were changed |
Renderers
Removed support for multiple renderers (svg & vml & a11y) for a single widget. If a widget wants to render differently on different platforms, there must be branching code inside the widget, or it needs to call a library that branches based on the browser type (like dojo.gfx or dojo.charting).
Templates
"this." is no longer used within ${} substitution notation. Just say ${foo} to access the foo attribute. dojoRoot,buildScriptBase,dojoModuleUrl are no longer supported, but any JavaScript properties on the widget's 'this' may be referenced with dotted notation.
The attributes dojoOn* are desupported (including dojoOnBuild); also can't use id attribute to affect a dojoAttachPoint.
dojoAttachEvent is case sensitive, so capitalization matters. You will probably have to change
dojoAttachEvent="onClick"to
dojoAttachEvent="onclick: onClick"(given that the event name is lowercase, and assuming that the method name is camel case)
Lists within dojoAttachPoint, dojoAttachEvent, waiRole, and waiState are now comma-separated (not separated by semi-colons)
Parent/Child relationships
By default widgets exist as islands, not knowing about their parent widget or children widgets. The exception is the destroyDescendants() function which will also delete all descendant widgets. Some widgets like Tree and SplitContainer know about their children, but those widgets will use the special mixins from Container.js
All custom widgets with children (and templates) must declare dojoAttachPoint=containerNode in the template. It doesn't default to domNode anymore.
Layout Widgets
Layout widgets mixin _LayoutWidget, and support a resize() method.
onResized() removed.
Miscellaneous Utility Functions
Many functions were removed from dojo core but added back into dijit. See HTML Utilities migration guide for details.
Also:
- dojo.widget.html.layout --> dijit.layout.layoutChildren (but layoutPriority flag was removed).
- Printer-friendly version
- Login or register to post comments
- Unsubscribe post

Typo: dojoModuleUri instead of dojoModuleUrl?
The old method was called dojoModuleUri, not dojoModuleUrl, no?
I found the bit on using template files confusing...
I found the bit on using template files confusing at first... What it means is that you need to add the class dijit._Templated as a "mix-in" class with something like
dojo.declare( "my.employer.FancyWidget", [dijit.form._FormWidget, dijit._Templated], { ... } );This "mixes in" the properties templateString and templatePath to the JS object of your custom widget. See the file /dijit/_Templated.js for details of the properties available.
srcNodeRef not srcDomNode
This page used to say use this.srcDomNode to reference the original node. It should have been this.srcNodeRef. Its fixed now - sorry for any confusion.