1

I'm wondering how to exactly change tab (core mage/tabs widget) programmatically. Docs say that I can use both activate and enable functions for that: http://devdocs.magento.com/guides/v2.0/javascript-dev-guide/widgets/widget_tabs.html

Unfortunately, no one is recognized.

Tabs are initialized as follows:

var tabs = $('.tabs');
tabs.tabs({
    openedState: 'active-tab'
});

Initialization and other base things work fine. The issue occurs when I would like to change tab programmatically:

tabs.activate('3'); // Uncaught TypeError: tabs.activate is not a function

I'm not sure what I am doing wrong.

  • How are you adding your JS? e.g via XML or Require? If you're using require what dependencies have you added? – Ben Crook Sep 28 '17 at 13:44
  • JS is added by data-mage-init attribute in phtml file. This is my dependencies in define/require block: define([ 'jquery', 'matchMedia', tabs'], function ($, mediaCheck, tabs) { .. }); – Rob Sep 28 '17 at 14:13
1

Inside vendor/magento/module-review/view/frontend/web/js/process-reviews.js:40 they are used like this:

$('.selector').tabs('activate', index);
  • Hey, @BenCrook thanks for your response! I missed it. This time code goes further without any errors, unfortunately still nothing happen with tabs. I use debugger to check how browser interpreted this code: tabs.tabs('activate' 114); - just go ahead, as if nothing was inside there. – Rob Sep 28 '17 at 14:22
  • Try adding a comma after 'activate'. If that still doesn't work to test the methods are working try $('.selector').tabs('destroy'). That should fully destroy the tabs. – Ben Crook Sep 28 '17 at 14:26
  • I have changed initialization method and finally, your approach starts working :) thanks! – Rob Oct 3 '17 at 8:20

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.