Covering up an Annoying Bug of Sidebar Widgets
December 24th, 2006 by Andrew Chen
I found there was always a Javascript
script error saying “’Draggables.drag[…].element.id’ is null or not an object” on the Sidebar Widgets page. I am using IE7. It doesn’t appear in Firefox. I am not alone. I found someone posted the same problem on wordpress.com. No one provided a solution.
Strictly speaking it is none issue because the script error seems doesn’t cause any functional problems. But I like everything looks perfect. So I provided a cover up of the error here. I don’t want to say it is a fix because I really don’t know what the code is supposed to do.
Here is the code in widgets.php that caused the error.
for (var n in Draggables.drags){
if (Draggables.drags[n].element.id == ‘lastmodule’){
Draggables.drags[n].destroy();
break;
}
}
The problem seems to be the variable “n” is not returning a number so when it is used as the subscript of an Array the Array returns nothing. In fact it also returns nothing on Firefox but interestingly Fireofox doesn’t report it as an error. So to cover it up I used “if (parseInt(n))” to wrap around the problem statement.
for (var n in Draggables.drags){
if (parseInt(n)) {
if (Draggables.drags[n].element.id == ‘lastmodule’){
Draggables.drags[n].destroy();
break;
}
}
}
It seems work. As I said I don’t really know how this piece of code interacts with others. If you don’t think that is a good practice or you have better idea please post.

(2 votes, average: 4.5 out of 5)
Hi,
You’re right man…
Thanks a lot! Your hint solved the bug!
I think You cold help so many other desperate users, if you post your hint on whe Wordpress board or even better if you give ist to the Widget author.
Thanks again!
Ilja