dojo dijit Tri-State Checkbox Widget

The link above is a demonstration of a dojo dijit Tri-State Checkbox Widget. It includes a nice button interface to test the properties, methods, and events of the widget, some documentation, and a link so you can download the widget and the test code.

It has been integrated into a complex application and is working well.

Interesting notes on this widget:

  • Spent time exploring how to indicate an indeterminate state for a checkbox. The de facto standard is a small box within the box, so that is what is implemented.
  • Widget is actually a text input that can contain the values on, off, or indeterminate.
  • Used a blank.gif to create the space in the focus node.
  • Value can be set by using a boolean (true=on, false=off), number (0=off, 1=on, 2=indeterminate), or string (off,on,indeterminate)
  • Checked maps to on, unchecked is considered off
  • Value is sent to the server regardless of input state. This is different than a traditional checkbox, where the value is only sent if the checkbox is checked.
  • Tried to avoid duplicating effort, used inheritance as much as possible.
  • Realized that even a ’simple’ widget involves significant complexity, and thorough testing is important prior to integration into pages.
  • Discovered that building a widget for dojo 1 does not build a widget for 0.9 - had to build a second copy for 0.9 to integrate into an older application.
  • Appreciated the dojo / dijit architecture, it made adding the widget a nice, efficient process.