April 6, 2006

Disabling XUL by section

I've often wanted to set one attribute on a XUL element and have that forcibly disable all the descendants of the XUL element at once. Given:

<xul:vbox sectiondisabled="true">
  <xul:textbox value="foo"/>
</xul:vbox>

the textbox should be disabled, in my opinion. (Or something like this.) So today I finally wrote up a script that could do this for me:

disableSection.js

I also learned about nsIDOMXULControlElement. My work in XUL Widgets could only benefit from implementing this.

There's a couple advantages to this. I can "nest" disabled sections now, so if a inner section is no longer disabled, the outer section still takes precedence. Also, if I replace my usage of disabled with sectiondisabled (on the same node), then I don't have to worry about accidentally and incorrectly setting a disabled property.

I still have to figure out how to handle <xul:command/> elements and command dispatchers, but by and large this is a big improvement.

Feedback welcome.

Posted by WeirdAl at April 6, 2006 12:20 PM
Comments

If this ever becomes part of the XUL core we'd need to make sure it works with our accessibility API support (MSAA and ATK). Most likely that would require some work. We expose the "disabled" state on each widget.

(From Alex: I don't foresee it becoming part of the XUL core by any means. I might wish otherwise, but I don't see it happening. The script I wrote is a hack, and probably doesn't affect anonymous controls.)

Posted by: Aaron Leventhal at April 11, 2006 11:08 AM