Opened 6 years ago

Closed 6 years ago

#17393 closed defect (fixed)

dojox.mobile.Accordion addChild method has a logical flaw

Reported by: mmckenziedev Owned by: Sebastien Brunot
Priority: undecided Milestone: 1.10
Component: DojoX Mobile Version: 1.9.1
Keywords: Cc:
Blocked By: Blocking:

Description

The standard behaviour of a widget is that we can add child widgets to the parent before a widget's startup method had been called. In dojox.mobile.Accordion.addChild we have this:

addChild: function(/*Widget*/ widget, /*int?*/ insertIndex){
        this.inherited(arguments);
        if(this._started){
                this._setupChild(widget);
                widget._at.startup();
                if(widget.selected){
                        this.expand(widget, true);
                        this.defer(function(){
                                widget.domNode.style.height = "";
                        });
                }else{
                        this.collapse(widget);
                }
        }
        this._addChildAriaAttrs();
}

We only call _setupChild from addChild when the widget has been started and this._started is true. In _setupChild we create an _AccordionTitle object for the child of the Accordion.

In _addChildAriaAttrs, we reference the _AccordionTitle object of the all the children of the Accordion object.

_addChildAriaAttrs: function(){
        var posinset = 1;
        var children = this.getChildren();
        array.forEach(children, function(child){
                domAttr.set(child._at.textBoxNode, "aria-posinset", posinset++);
                domAttr.set(child._at.textBoxNode, "aria-setsize", children.length);
        });
}

But as we can see from addChild, we will call _addChildAriaAttrs wether the widget has been started or not, and wether _setupChild has been called on a child widget or not.

So to conclude, _addChildAriaAttrs will get called on a child element which does not have an _AccordionTitle created for it, so we will get an error from the browser like:

Cannot read property 'textBoxNode' of undefined

because child._at.textBoxNode will not exist because child._at has not been set and so it is undefined.

My suggestion would be to place _addChildAriaAttrs inside the conditional this._started block of addChild.

Attachments (1)

Accordion.js (15.7 KB) - added by mmckenziedev 6 years ago.
Accordion.js with the error fixed

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by mmckenziedev

Attachment: Accordion.js added

Accordion.js with the error fixed

comment:1 Changed 6 years ago by Patrick Ruzand

Milestone: tbd1.10
Owner: set to Patrick Ruzand
Status: newassigned

comment:2 Changed 6 years ago by Patrick Ruzand

Do you have signed a CLA ?

comment:3 Changed 6 years ago by Patrick Ruzand

Owner: changed from Patrick Ruzand to Sebastien Brunot

comment:4 Changed 6 years ago by Sebastien Brunot

A pull request has been created to fix this issue: https://github.com/dojo/dojox/pull/73

comment:5 Changed 6 years ago by Patrick Ruzand <pruzand@…>

Resolution: fixed
Status: assignedclosed

In b1aa28393ca4794f1ff5b4d3e3afa17e4ce0352d/dojox:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.