Results 1 to 4 of 4

Thread: namespace for a function

  1. #1
    Ext User
    Join Date
    Jun 2009
    Posts
    18

    Default namespace for a function

    Hi,

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

    Code:
    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:
    // 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

  2. #2
    Ext JS Premium Member
    Join Date
    May 2007
    Posts
    698

    Default

    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) :

    PHP Code:
    Ext.ns('foo.bar');

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

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

  3. #3
    Ext User
    Join Date
    Jun 2009
    Posts
    18

    Default [SOLVED]

    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.

  4. #4
    Ext JS Premium Member
    Join Date
    May 2007
    Posts
    698

    Default

    Quote Originally Posted by dke01 View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •