3

I have created a new component. At the administrator backend, the active tab goes back to the first tab (which was declared in edit.php) when I click on 'save' after I have modified a field in another tab.

I trace my codes, and it follows similarly to that in contents (/article/views/tmpl/edit.php) and weblinks (/weblink/views/tmpl/edit.php), where the active tab works; meaning it stays at the same tab after "save". I am using Joomla 3.3.6

Here's an extract of my codes...

defined('_JEXEC') or die;

// Include the component HTML helpers.
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

JHtml::_('behavior.formvalidation');
// JHtml::_('behavior.keepalive');
JHtml::_('formbehavior.chosen', 'select');

?>

<script type="text/javascript">
Joomla.submitbutton = function(task)
{
    if (task == 'subscription.cancel' ||     document.formvalidator.isValid(document.id('item-form')))
    {
        <?php echo $this->form->getField('description')->save(); ?>
        Joomla.submitform(task, document.getElementById('item-form'));
    }
}
</script>

<form action="<?php echo JRoute::_('index.php? option=com_subscriptions&view=subscription&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="item-form" class="form-validate">

<?php echo JLayoutHelper::render('joomla.edit.title_alias', $this); ?>

  <div class="form-horizontal">
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>         

    <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', empty($this->item->id) ? JText::_('COM_SUBSCRIPTIONS_NEW_SUBSCRIPTION', true) : JText::_('COM_SUBSCRIPTIONS_EDIT_SUBSCRIPTION', $this->item->id, true)); ?>
    <div class="row-fluid">
        <div class="span9">
......

    <input type="hidden" name="task" value="" />

2

On the third last line above

    <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', empty($this->item->id) ? JText::_('COM_SUBSCRIPTIONS_NEW_SUBSCRIPTION', true) : JText::_('COM_SUBSCRIPTIONS_EDIT_SUBSCRIPTION', $this->item->id, true)); ?>

I think it should be

JText::sprintf('COM_SUBSCRIPTIONS_EDIT_SUBSCRIPTION', $this->item->id, true)

instead of

JText::_('COM_SUBSCRIPTIONS_EDIT_SUBSCRIPTION', $this->item->id, true)
1

I added the following code to my administrator/component/com_/view/ file:

/* tab memory */
jQuery(function($) {
  var json, tabsState;
  $('a[data-toggle="pill"], a[data-toggle="tab"]').on('shown', function(e) {
    var href, json, parentId, tabsState;

    tabsState = localStorage.getItem("tabs-state");
    json = JSON.parse(tabsState || "{}");
    parentId = $(e.target).parents("ul.nav.nav-pills, ul.nav.nav-tabs").attr("id");
    href = $(e.target).attr('href');
    json[parentId] = href;

    return localStorage.setItem("tabs-state", JSON.stringify(json));
  });

  tabsState = localStorage.getItem("tabs-state");
  json = JSON.parse(tabsState || "{}");

  $.each(json, function(containerId, href) {
    return $("#" + containerId + " a[href=" + href + "]").tab('show');
  });

  $("ul.nav.nav-pills, ul.nav.nav-tabs").each(function() {
    var $this = $(this);
    if (!json[$this.attr("id")]) {
      return $this.find("a[data-toggle=tab]:first, a[data-toggle=pill]:first").tab("show");
    }
  });
});

from this discussion: https://stackoverflow.com/a/16984739/1729791 and its working for me

-3

Add this in top: JHtml::_('behavior.tabstate');

1
  • I don't know enough to claim that this answer is incorrect, but the 2 downvotes give some indication. Beyond the correctness, whenever you wish to post an answer here, please take care to include a thoughtful and educational explanation of why/how your solution works (to the best of your knowledge).
    – mickmackusa
    Jul 20 '18 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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