Results 1 to 3 of 3

Thread: Suppress error when container element doesn't exist

  1. #1

    Default Suppress error when container element doesn't exist

    Hello,

    On some of the pages on my website I have a TabPanel; some I don't. How can I structure my code so that an error isn't triggered on the pages that don't? In the code below I get an "this.el has no properties" error in Firebug if #tab-panel doesn't exist in the page. (I didn't think it was necessary to include the full Firebug error output.) Also, is there a better way to initialize widgets than the method I've used?

    Thanks!

    Code:
    // reference local blank image
    Ext.BLANK_IMAGE_URL = '/images/s.gif';
    
    // create namespace
    Ext.namespace('Acme');
    
    Acme.app = function() {
    
      return {
    
        init: function() {
          var tabPanel = new Ext.TabPanel({
            applyTo: 'tab-panel',
            autoTabs: true,
            deferredRender: false,
            activeTab: 0
          });
        }
    
      };
    }();
    
    // Run Acme.app.init with scope Acme.app
    Ext.onReady(Acme.app.init, Acme.app);

  2. #2
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246

    Default

    Use:

    Code:
    var el = Ext.get('tab-panel');
    if (el) {
      var tabPanel = new Ext.TabPanel({
        autoTabs: true,
        deferredRender: false,
        activeTab: 0
      });
      tappanel.appyToMarkup(el);
    }

  3. #3

    Default

    Easy as that! Thanks, Condor!

Posting Permissions

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