Solved

How to keep parent tab selected when nested tab is clicked?

Posted on 2016-09-28
8
20 Views
Last Modified: 2016-10-08
Experts,

I am using the jQueryMobile framework.

I'm nesting tabs using the code below. When clicked the "Facility" tab reveals the nested tabs and loads the content for the "Source 1" tab.

The issue I am trying to solve is two fold:

1) I want to make sure that the "Source 1" tab is activated when the "Facility" tab is selected because the "Source 1" content loads by default.

2) If any of the nested tabs are selected (Source 1, Source 2, Source 3,...Source 7) I want to ensure the "Facility" tab remains selected.

I assume that this is best done by modifying the CSS with jQuery but, I am not sure.

Any help would be appreciated.

<!-- TAB CONTENT -->
<div data-role="tabs" id="tabs">
    <!-- MAIN HEADER NAVIAGATION -->
    <div data-role="navbar">
        <ul>
            <li><a href="scripts/content.php?by_source" data-ajax="false" class="ui-btn-active">Resource</a></li>
            <li><a href="#facility" data-ajax="false" id="departments_by_facility_tab">Facility</a></li>
        </ul>
    </div>
    <!-- END MAIN HEADER NAVIGATION -->
    
    <!-- FACILITY TAB -->
    <div id="facility">
        <div data-role="tabs" id="facility_tabs">
            <div data-role="navbar">
                 <ul>
                    <li><a href="scripts/content.php?source=1" data-ajax="false" class="ui-btn ui-shadow">Source 1</a></li>
                    <li><a href="scripts/content.php?source=2" data-ajax="false" class="ui-btn ui-shadow">Source 2</a></li>
                    <li><a href="scripts/content.php?source=3" data-ajax="false" class="ui-btn ui-shadow">Source 3</a></li>
                    <li><a href="scripts/content.php?source=4" data-ajax="false" class="ui-btn ui-shadow">Source 4</a></li>
                    <li><a href="scripts/content.php?source=5" data-ajax="false" class="ui-btn ui-shadow">Source 5</a></li>
                    <li><a href="scripts/content.php?source=6" data-ajax="false" class="ui-btn ui-shadow">Source 6</a></li>
                    <li id="mdo_tab"><a href="scripts/content.php?source=7" data-ajax="false" class="ui-btn ui-shadow">Source 7</a></li>
                </ul>
            </div>
        </div>
    </div>              
    <!-- END FACILITY TAB -->
</div>
<!-- END TAB CONTENT -->

Open in new window

0
Comment
Question by:evibesmusic
  • 4
  • 4
8 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41821191
Not sure I understand the problem

1) Source 1 will be selected for Facility - what am I missing

2) When selecting sub tabs Facility remains selected - again what am I missing?
0
 

Author Comment

by:evibesmusic
ID: 41822407
@Julian:

Sorry...here is a fiddle to show what I am speaking of: Fiddle

When the "Facility" tab is clicked for the first time after page load it does two things:
- Activates and turns blue
- Loads the nested tabs (Source 1, Source 2, etc.)

When the "Facility" tab is clicked for the first time after page load it should also do the following:
- Activate the Source 1 tab because the Source 1 tab content displays by default when the nested tabs are initialized for the first time.

Additionally, when any of the nested tabs are selected the "Facility" tab loses its activated state. I want it to stay activated.
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41822649
I put this sample together based on your OP - Is that what you are referring to about the tabs staying activated?

I still don't understand this bit
- Activate the Source 1 tab because the Source 1 tab content displays by default when the nested tabs are initialized for the first time.
Why does it need to be activated if it is displayed by default when the tabs are initialised?
0
 

Author Comment

by:evibesmusic
ID: 41822671
@Julian:

Your demo won't come up for me?

When I say "activate" I should have said make the button appear in the on state or "Blue" as it looks like when it is clicked.

I simply want the Facility tab and the Source 1 tab to look as if they have been clicked.

Then if any other Source tab is clicked, I want the Facility tab to remain in the on state and look like it has been clicked.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Accepted Solution

by:
evibesmusic earned 0 total points
ID: 41822716
@All:

This seems to be doing the trick but, the function doesn't fire the first time a nested tab is clicked. The function only fires the second time you click on a nested tab.

Fiddle
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41822743
What happens when you try the sample URL ? I have tested again and it seems to be fine.
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41822745
I am using the jQueryMobile framework.
Just saw this - will have to rework sample ...
0
 

Author Closing Comment

by:evibesmusic
ID: 41834909
The fiddle provided adequately answers the question.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now