PDA

View Full Version : [CLOSED-692] Context menu on tree not showing in IE 7 / IE 8 + workaround



MischaKroon
6 Mar 2010, 5:21 AM
[ deleted ugly spaghetti code. see post #3 ]

Jamie Avins
8 Mar 2010, 9:37 AM
Please follow this guide as it is very difficult to read this message currently:

http://www.extjs.com/forum/showthread.php?t=71015

MischaKroon
8 Mar 2010, 9:56 AM
Ext version tested:

Ext 3 rev 1.1


Adapter used:

jquery


css used:

only default ext-all.css




Browser versions tested against:

IE7
IE8
FF3.6 (firebug 1.5.2 installed)
Opera 10.5
Chrome 4


Operating System:

Windows7


Description:

Javascript error on trying to show contextmenu, only happening in IE7 / IE8


Test Case:



var buildCtxMenu =function(){
returnnew Ext.menu.Menu({

items:
[{itemId:'add',handler: onAddNode},
{itemId:'addArticle',handler: onAddArticle},
{itemId:'edit',handler: onEdit,scope: onEdit},
{itemId:'delete',handler: onDelete},
]
});
}

----
var onCtxMenu = function(node, evtObj) {
node.select();
evtObj.stopEvent();

if (! this.ctxMenu) {
this.ctxMenu = buildCtxMenu();
}

var ctxMenu = this.ctxMenu;
var addItem = ctxMenu.getComponent('add');
var addArticle = ctxMenu.getComponent('addArticle');
var editItem = ctxMenu.getComponent('edit');
var deleteItem = ctxMenu.getComponent('delete');

addItem.setText('Toevoegen Categorie');
addArticle.setText('Toevoegen Artikel');
editItem.setText('Wijzigen Categorie');
deleteItem.setText('Verwijderen Categorie');

addArticle.enable();
addItem.enable();
editItem.enable();
deleteItem.enable();
}
ctxMenu.showAt(evtObj.getXY()) ;



See this URL : http://


Steps to reproduce the problem:

Make a tree in js use above code to make a context menu
Right click on treenode


The result that was expected:

Show context menu


The result that occurs instead:

JS Error


Debugging already done:

it breaks on:
extjs-all-debug.js
Line 55420:


else if(c.tagName || c.el)

Which is because somehow c is undefined.
Added the following line above this to make sure the menu gets shown but with an extra separator at the end


if (c == undefined) {
return new Ext.menu.Separator();
}



Possible fix:

Full changed function:


// private
lookupComponent : function(c){
if(Ext.isString(c)){
c = (c == 'separator' || c == '-') ? new Ext.menu.Separator() : new Ext.menu.TextItem(c);
this.applyDefaults(c);
}else{
if (c == undefined) {
return new Ext.menu.Separator();
}
if(Ext.isObject(c)){
c = this.getMenuItem(c);
}
else if(c.tagName || c.el){ // element. Wrap it.
c = new Ext.BoxComponent({
el: c
});
}
}
return c;

Jamie Avins
8 Mar 2010, 10:47 AM
What a difference! Thanks.

evant
6 Apr 2010, 1:48 AM
This isn't a bug. You have an extra comma at the end, which IE interprets as undefined:



var x = [1, 2, 3, 4,];
alert(x.length);


Run that in FF and IE.

Marking as closed.