Results 1 to 6 of 6

Thread: Prevent tabchange

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    88
    Vote Rating
    4
      0  

    Default Answered: Prevent tabchange

    Hi,

    I'm looking for a way to prevent a tab change.
    I tried to hook into tabchange event but it won't fire.
    Is it possible to prevent the change by using tabchange?
    What am I missing?

    Code:
    Ext.application({
        launch : function() {
            
    var panel = Ext.create('Ext.TabPanel', {
        fullscreen : true,
        tabBarPosition: 'bottom',
        config: {
            tabBar : {
                tabchange : {
                    activate:  function(container, newTab, oldOTab, opts) {
                    alert('active');
                    }
                }
            }
        },
            items : [ 
            {
                docked : 'top',
                xtype : 'toolbar',
                itemId: 'topBar',
                title : 'title',
                items : [ {
                    xtype : 'button',
                    itemId : 'backBt',
                    text : 'back',
                    ui : 'back'
                } ]
            },         
            {
                xtype: 'carousel',
                itemId: 'carouselPanel',
                title: 'Home',
                iconCls: 'home',
                layout : {
                    type: 'card'
                },
    
    
                items: [ {
                    xtype: 'panel',
                    itemId: 'carousel1',
                    html: 'carousel1',
                    
                }, 
                {
                    xtype: 'panel',
                    itemId : 'carousel2',
                    html: 'carousel2',
                    
                }                    
                ] 
                
            },
            {
                xtype: 'panel',
                title: 'User',
                iconCls: 'user',
                html: 'User Tab',
                //hidden : true
               }
            ]
            
        
    });
        }
    });

  2. You will need to listen for activeitemchange on the tabpanel and return false.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,857
    Answers
    3968
    Vote Rating
    1322
      0  

    Default

    You will need to listen for activeitemchange on the tabpanel and return false.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    88
    Vote Rating
    4
      0  

    Default

    Thx. It works. Here is my solution.
    In my controllers init -> control function I react to the itemchange:

    Code:
      myview : {
         			activeitemchange : function(container, value, oldValue, opts) {
        				console.log('tab change');
        				var status = true;
        				if(value.getItemId() === 'mytab') {
        					status = this.getApplication().getController('Order').refreshCart();
        				}
        				
        				if(status === false) {
        					    this.getMyView().setActiveItem(oldValue);					
        				}
        				
        				return status;
        			}
        		}

  5. #4
    Sencha Premium Member
    Join Date
    May 2012
    Location
    India
    Posts
    6
    Vote Rating
    0
      0  

    Default

    Hi,

    I am also performing one check on activeitemchange event. If the check condition returns false the current tab should remain intact otherwise the selected tab contents should get displayed. In my controller I am writing:

    Code:
    onModuleChange: function(tabpanel, newModule, previousModule){
            
        if(newModule.getItemId() === 'myModuleId'){
            if(myClass.checkMyCondition()){
                return true;
            } else {
                return false;
            }
        }
    }

    I see that when myCheckCondition() returns false the activeItem in tabpanel object does not change, content of tabpanel does not change but the highlight of the button on tab bar changes. Please tell me if I am doing something wrong or something extra needs to be done.

    Regards,
    Rajat Srivastava

  6. #5
    Sencha Premium Member
    Join Date
    Aug 2013
    Posts
    12
    Vote Rating
    0
      0  

    Default

    rejjy1980: did you ever solve this issue? I'm experiencing the same behaviour.

  7. #6
    Sencha Premium Member
    Join Date
    May 2012
    Location
    India
    Posts
    6
    Vote Rating
    0
      0  

    Default

    Hi,

    Please try this code. It worked for me

    Code:
    onModuleChange: function(tabpanel, newModule, previousModule){
        var myTabBarActiveTab = tabpanel.getTabBar().getActiveTab();    
        if(newModule.getItemId() === 'myModuleId'){
            if(myClass.checkMyCondition()){
                return true;
            } else {
                return false;
         tabpanel.getTabBar().setActiveTab(myTabBarActiveTab);
            }
        }
    }

Posting Permissions

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