2

I'm working on a Joomla component and need help in redirecting to specific tab.

I have created multiple tabs in my view using bootstrap (eg: JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'tab1')). I can set the default active tab by passing 'active' => 'tabname'. However, I want to control this dynamically after any actions performed on the view in any specific tab.

For example, if the user clicks the save button while in Tab3, I want to return to Tab3 after the save action completes. Currently it goes back to tab1 as I set that as default.

Can anyone help me how to identify the current tab and redirect to the same tab after any action by the user?

0

1 Answer 1

1

You have to pass the tab where you are in the link.

I did it once like this:

$jinput = JFactory::getApplication()->input; 
$tab    = $jinput->getString('tab', 'info');

$tabinfo  = false;
$tabphoto = false;
$tabmap   = false;

if ($tab == 'photos')
{
    $tabphoto = true;
} 
elseif ($tab == 'map') 
{
    $tabmap = true;
}
else
{
    $tabinfo = true;
}

The HTML:

<ul class="nav nav-tabs">

    <li class="<?php echo ($tabinfo)?'active':''?>">
        <a href="#info" data-toggle="tab">
            <?php echo JText::_('WBS_COMPANY_INFO');?>
        </a>
    </li>

    <li class="<?php echo ($tabphoto)?'active':''?>">
        <a href="#photos" data-toggle="tab">
            <?php echo JText::_('WBS_COMPANY_PHOTOS');?>
        </a>
    </li>

    <li class="<?php echo ($tabmap)?'active':''?>">
        <a href="#map" data-toggle="tab">
            <?php echo JText::_('WBS_COMPANY_MAP');?>
        </a>
    </li>

</ul>

<div class="tab-content">

     <div id="info" class="tab-pane <?php echo ($tabinfo)?'active':''?>">
     </div>

     <div id="photos" class="tab-pane <?php echo ($tabphoto)?'active':''?>">
     </div>

     <div id="map" class="tab-pane <?php echo ($tabmap)?'active':''?>">
     </div>

</div>
2
  • JRequest is deprecated! This also doesn't utilise JHtml...it's hardcoded
    – Lodder
    Commented Nov 22, 2016 at 15:01
  • I corrected the jrequest, I hope it helps even is not JHtml Commented Nov 22, 2016 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.