EasyUI Forum
April 28, 2024, 01:15:16 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Tab onSelect is fired onLoad  (Read 29421 times)
pacific202
Newbie
*
Posts: 35


View Profile
« on: December 03, 2011, 06:56:53 PM »

I have nested tabs, and it looks like the first tab in each tab group is loading when

Tab A1
  - Tab B1
  - Tab B2
Tab A2
  - Tab C1
  - Tab C2
  - Tab C3
Tab A3
  - Tab D1
  - Tab D2

When a page with these tabs loads, the onSelect event will fire for D1, but A1 and B1 are actually the visible tabs
« Last Edit: December 03, 2011, 06:59:24 PM by pacific202 » Logged
pacific202
Newbie
*
Posts: 35


View Profile
« Reply #1 on: December 04, 2011, 08:17:50 AM »

I was able to work around this by adding the onSelect event assignment into the onSelect event of the parent tab.
Logged
tslatt
Jr. Member
**
Posts: 85



View Profile
« Reply #2 on: December 06, 2011, 07:43:40 AM »

Could you provide the code of your workaround, please?
Logged
pacific202
Newbie
*
Posts: 35


View Profile
« Reply #3 on: December 11, 2011, 10:14:59 PM »

I'll gladly post it after one quick refactor in the next few days.
Logged
pacific202
Newbie
*
Posts: 35


View Profile
« Reply #4 on: January 11, 2012, 06:32:26 PM »

Sorry, I had forgotten about this.

Code:
     $("#tab-container").tabs({

        "onSelect": function(title){

            if(lastTab != null){
                eval(lastTab + "_OnUnload()")
            }

            eval(util_Simplify(title) + "_OnSelect()");
            lastTab = util_Simplify(title);

        }           
     });

util_Simplify goes through a string and puts everything to lower case and removes all spaces.  The next version of my code will have objects that manage the content for each tab, and that can be handled easily with the code above by changing the _OnUnload() to .OnUnload().
Logged
pacific202
Newbie
*
Posts: 35


View Profile
« Reply #5 on: January 11, 2012, 06:51:49 PM »

I just saw that was an older version of my code.  Instead of $("#tab-container") I just used the class selector on all jeasyui-tab elements.  It works great.
Logged
tslatt
Jr. Member
**
Posts: 85



View Profile
« Reply #6 on: January 13, 2012, 12:32:24 PM »

Thanks for posting this. I'm having trouble understanding it, though. Could you please explain the two lines that start with "eval"? I'm not sure what those are doing. Thank you so much!

Code:
     $("#tab-container").tabs({

        "onSelect": function(title){

            if(lastTab != null){
                eval(lastTab + "_OnUnload()")
            }

            eval(util_Simplify(title) + "_OnSelect()");
            lastTab = util_Simplify(title);

        }           
     });
Logged
pacific202
Newbie
*
Posts: 35


View Profile
« Reply #7 on: February 15, 2012, 10:57:48 AM »

eval will dynamically execute JavaScript code, please note that using it is frequently debated because it can be used to maliciously execute code, but in this case I'm getting it to dynamically call a function which is pretty straightforward.

Let's say I have two tabs, abc and def.  I would then create four functions:

function abc_OnSelect() {}
function abc_OnUnload() {}
function def_OnSelect() {}
function def_OnUnload() {}

The code below will execute the appropriate function when a tab is loaded or unloaded.  I could also add some code in there to have the _OnUnload function return a false if there is some condition that should prevent the new tab to load.

Make sense?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!