#412 closed defect (fixed)
ToolbarButtonGroup doesn't set itself up fully when constructed from markup
Reported by: | Laurie Harper | Owned by: | anonymous |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Widgets | Version: | 0.2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
ToolbarButtonGroup? doesn't connect the onSelect event or apply its defaultButton property if its children are created using markup rather than by calling addChild. As a result, the default button will not be selected, and clicking on a child button will not deselect the selected button.
Here's a patch to fix it:
Index: src/widget/Toolbar.js =================================================================== --- src/widget/Toolbar.js (revision 3021) +++ src/widget/Toolbar.js (working copy) @@ -561,18 +561,28 @@
if this is set to a number, the button at that index will be selected this.defaultButton = "";
- var oldAddChild = this.addChild;
+ this.postCreate = function() { + for (var i = 0; i < this.children.length; i++) { + this._injectChild(this.children[i]); + } + } + + var oldAddChild = this.addChild;
this.addChild = function(item, pos, props) {
var widget = dojo.widget.ToolbarItem?.make(item, null, dojo.lang.mixin(props {}, {toggleItem:true}));
- dojo.event.connect(widget, "onSelect", this, "onChildSelected");
var ret = oldAddChild.call(this, widget, null, pos, null);
+ this._injectChild(widget); + return ret; + } + + this._injectChild = function(widget) { + dojo.event.connect(widget, "onSelect", this, "onChildSelected");
if(widget._name == this.defaultButton
(typeof this.defaultButton == "number" && this.children.length-1 == this.defaultButton)) { widget.select(false, true);
}
- return ret;
- }
+ }
this.getItem = function(name) {
if(name instanceof dojo.widget.ToolbarItem?) { return name; }
Thanks for the patch. Checked in as #3158.