Opened 8 years ago

Closed 8 years ago

#14098 closed defect (fixed)

error of null property in scrollable.js findDisp()

Reported by: zhangyp Owned by: ykami
Priority: high Milestone: 1.7
Component: DojoX Mobile Version: 1.7.0b1
Keywords: Cc: basselmourjan@…, Chris Mitchell, Atsushi Ono
Blocked By: Blocking:

Description

The user reported null property problem in scrollable.js. I checked the latest nightly code. It does not do checking on parentNode in findDisp(). And it would be easy to provide a fix for that.

Hi,

I just downloaded the rc1 code and while preforming a transition to a dynamic ScrollableView?,

I encountered the following error "Cannot read property 'childNodes' of null".

so after tracing it back, I found that it was caused by the findDisp() found in dojox.mobile.scrollable

where it does not check if domeNode has a parent or not before accessing it's children nodes.

concerning the scenario, it is similar to the case that I addressed earlier with PerformTransition? issue #14082,

but earlier I was dealing with View and SwapView? only.

Anyways after modifying findDisp() code and checking if parent node exists, problem was solved!

Regards,

Change History (3)

comment:1 Changed 8 years ago by bill

Component: GeneralDojoX Mobile
Owner: set to ykami

comment:2 Changed 8 years ago by ykami

Cc: Atsushi Ono added
Milestone: tbd1.7
Status: newassigned

Bassel, thanks for posting the sample code to dojo-interest. It looks the problem is about widget instantiation sequence, not about view transitions.

In general, recommendation for dynamic widget creation is to instantiate widgets 'on-line', I mean while dom nodes are connected to somewhere in the document. If you did it 'off-line', I mean 'in the air', something unwanted might happen, because, for example, the browser cannot determine dimension of some nodes.

For example, as shown below, if you create an 'on-line' node first, and then create a view based on that node, the problem would not happen.

var node = dojo.create("div", null, dojo.body());
var view1 = new dojox.mobile.ScrollableView({
    id: "foo",
    selected: true
}, node);
var heading2 = new dojox.mobile.Heading({
    label: "Fixed View Footer",
    fixed: "bottom"
});
view1.addChild(heading2);

Another solution would be to create a view first, and then immediately append its domNode to somewhere, before working with Heading. This should solve the problem too.

dojo.body().appendChild(view1.domNode);

All that said, I will add the parent check code for safety. But I recommend you to not rely on this fix. The above examples should be safer and work better.

comment:3 Changed 8 years ago by ykami

Resolution: fixed
Status: assignedclosed

In [26878]:

Fixes #14098 !strict. Added parent existence check code. Parent can be null when view is created in the air, and some child widget is added to it.

Note: See TracTickets for help on using tickets.