PDA

View Full Version : [UNKNOWN][3.0.3] Ext.Element setWidth cannot handle NaN



ssmout
30 Nov 2009, 8:45 AM
When the setWidth method of an Ext.Element is called with the width NaN, this breaks MSIE. Specifically, the line in setWidth



me.dom.style.width = me.addUnits(width)
has a JavaScript error when the right side is not a string that MSIE recognizes as a valid CSS width, e.g. NaN or 'NaNpx'. (Firefox, on the other hand, apparently just treats an unrecognized value as 'auto'.)

A fix would be as simple as adding the following to the beginning of setWidth:



if (isNaN(width)) {
width = 'auto';
}
or something similar in adjustWidth.

This issue was discussed in 2008; see http://www.extjs.com/forum/showthread.php?t=42037. They seem to have concluded that this is not a bug, but I disagree. At the very least, it is a small enhancement that would make things more bug-resistant. I've had this issue come up several times, first in a grid that was supposed to have automatic width, and more recently using the livegrid extension. It can be rather difficult to debug, as usually one is not deliberately setting a width to NaN, but this sometimes happens when no width has been set, particularly when using extensions. For example, with my livegrid problem today, the width in question was actually the scrollOffset on the GridView, which is not something that I've ever needed to set before.

Condor
30 Nov 2009, 11:48 PM
This has been discussed before.

setWidth and setHeight shouldn't be called with NaN. The code that calls setWidth or setHeight with NaN is buggy (most, if not all, of these instance should be fixed in the upcoming Ext 3.1).

ssmout
1 Dec 2009, 6:21 AM
I know it's been discussed before, which is why I pointed out where it has been discussed before. My point is that there are places in Ext itself but also in third party libraries that do call it with NaN. Even if many of those are fixed, it's easy to miss some, and probably easy to introduce new ones. Is the check for NaN really so slow that it's not worth the time it would save me and presumably other developers who have had this issue?