PDA

View Full Version : namespace for a function



dke01
14 Jul 2009, 4:42 PM
Hi,

I have a problem referencing a function within a namespace from a key handler



Ext.ns('foo.bar');

foo.bar.bindGrid = function() {
alert('hello');
}
I then want to call this function from a submit button by either click or pressing enter


// Code for button
foo.bar.submit = foo.bar.searchContent.addButton({
text: 'Search',
handler: function() {
foo.bar.bindGrid();
}
});

// code to handle enter key
foo.bar.searchContent = new Ext.form.FormPanel({
.....
keys: [{
key: Ext.EventObject.ENTER,
fn: foo.bar.bindGrid
}]
});


This code works when not using a namespace.
With a namespace clicking the submit button works, but pressing enter on the keyboard now throws an error fn has no properties
Also is foo.bar.bindGrid = function() the correct way to put a function in a namespace I have not been able to find any namespace examples that use functions only variables.

TIA
p.s I am new to ExtJS.

Dave

danh2000
14 Jul 2009, 5:11 PM
You've snipped your code so I can't see exactly what you've done wrong, but the following works perfectly (It's only slightly modified so I could get a working version pasted into Firebug) :


Ext.ns('foo.bar');

foo.bar.bindGrid = function() {
alert('hello');
}

foo.bar.searchContent = new Ext.form.FormPanel({
renderTo: document.body,
items: {
fieldLabel: 'Dummy',
xtype: 'textfield'
},
keys: [{
key: Ext.EventObject.ENTER,
fn: foo.bar.bindGrid
}]
});

dke01
14 Jul 2009, 5:30 PM
Thanks Once again for solving my problem.

Using your simple example with Firebug and rendering to document.body made debugging this much easier.

The issue was my own fault the only difference between my demo code and my Real code is that I was defining
foo.bar.bindGrid after the formPanel instead of before it.

There seems to be a BUG with these forums, They will not allow me to allocate you any more reputation points until I spread them around to other people. Not real fair considering your the one who always solves my problems.

danh2000
14 Jul 2009, 5:39 PM
Thanks Once again for solving my problem.
...
There seems to be a BUG with these forums, They will not allow me to allocate you any more reputation points until I spread them around to other people. Not real fair considering your the one who always solves my problems.

No problem! - Pure chance, there are lot's of helpful people here, but thanks for the consideration ;)